Chapter 29: ASP Syntax

1. What is “ASP Syntax” really about?

ASP Syntax = the rules that tell the server how to separate:

  • normal HTML (which is sent to the browser unchanged)
  • server-side code (which runs on the server and can generate dynamic HTML)

In Classic ASP, this separation is done with special tags:

Tag Purpose When to use it
<% … %> Server-side code block (VBScript / JScript) For logic, variables, loops, conditions
<%= expression %> Shortcut to output (print) a value To insert dynamic values into HTML
<!– #include … –> Include other .asp / .inc files To reuse common code (header, footer)

Everything outside <% %> is sent directly to the browser as HTML.

Everything inside <% %> is executed on the server — never visible to the browser.

2. The Golden Rule – Browser sees only HTML

No matter how much server code you write, the final response is pure HTML + CSS + JavaScript. The browser never sees <%, never sees VBScript, never sees Response.Write.

This is the #1 thing beginners misunderstand.

3. First Real Example – Hello World with Syntax

File name: hello.asp

asp

What the browser receives (View Source in browser):

HTML

→ No trace of <%, Dim, Response.Write, Server.HTMLEncode — all gone!

4. Most Important Syntax Elements (with Examples)

A. <% … %> – Code block (logic, variables, loops, conditions)

asp

asp

C. Mixing code and HTML (very typical pattern)

asp

→ Notice how code blocks and HTML alternate — very common in Classic ASP.

D. <!– #include file=”…” –> – Include files

Very important for reuse (header, footer, database connection, functions)

asp

header.inc might contain:

asp

5. Teacher Summary – ASP Syntax in One Page

Classic ASP Syntax (what W3Schools teaches in “ASP Syntax”):

  • <% … %> → run VBScript code (variables, If, For, loops, Response.Write)
  • <%= expression %> → print a value safely into HTML
  • <%@ Language=VBScript %> → at very top (optional)
  • Option Explicit → force variable declaration (very good habit)
  • Server.HTMLEncode() → prevent XSS (almost always used with user input)
  • Request.Form(“key”), Request.QueryString(“key”), Session(“key”) → get data
  • <!– #include … –> → reuse code across pages

Browser sees only HTML — all <% %> code disappears.

This syntax powered millions of websites 1998–2010 and is still alive in many old Indian banking/government/ERP systems in 2026.

Questions for next class?

  • Want to see a full login system in Classic ASP (very typical 2000s code)?
  • Or database connection + recordset loop in detail?
  • Or compare Classic ASP syntax vs Razor syntax side-by-side?
  • Or shall we move back to Razor / modern .NET?

Just tell me — I’m here! 🚀🇮🇳 Happy learning, Webliance! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *