Syntax and Semantics
ASP.NET is fully API-compatible with traditional ASP, with the following three exceptions:
- Request(): ASP returns an array of strings; ASP.NET returns a string.
- Request.QueryString(): ASP returns an array of strings; ASP.NET returns a string.
- Request.Form(): ASP returns an array of strings; ASP.NET returns a string.
In ASP, the Request, Request.QueryString, and Request.Form collections return string arrays from lookups. For example, in traditional ASP the query string values from a request to http://localhost/test/Test.asp?values=45&values=600 would be accessed as follows:
<%
' Below line outputs: "45, 600"
Response.Write Request.QueryString("values")
' Below line outputs: "45"
Response.Write Request.QueryString("values")(1)
%>
In ASP.NET, these collections require an explicit method to get array access. These arrays are also now 0-index based. For example, in ASP.NET the query string values from a request to http://localhost/test/Test.aspx?values=45&values=600 would be accessed as follows:
<%
' Below line outputs: "45, 600"
Response.Write(Request.QueryString("values"))
' Below line outputs: "45"
Response.Write(Request.QueryString.GetValues("values")(0))
%>
VB
These arrays are most commonly used when form values are posted from multiselect list boxes (<select multiple>) or when multiple check boxes have the same name.
Semantic Differences Between ASP.NET and ASP
ASP.NET pages also have several semantic changes from existing ASP pages. The following issues are the ones most likely to affect you:
- ASP.NET pages only support a single language.
ASP allowed multiple languages to be used on a single page, which was useful for script library
scenarios. Because of ASP.NET's compiled nature, it supports only a single language on a page.
However, it is still possible to have multiple pages, each with a separate language, within a single application. User Controls might also have a different language from the page that contains them. This enables you to integrate functionality written in different languages in a single page. This is an adequate substitute for the multiple-language Include files that are prevalent in traditional ASP applications.
- ASP.NET page functions must be declared in <script runat=server> blocks.
In ASP, page functions could be declared within <% %> blocks:
<%
Sub DoSomething()
Response.Write "Hello World!"
End Sub
DoSomething
%>
In ASP.NET, page functions must be declared in <script runat=server> blocks:
<script language="VB" runat=server>
Sub DoSomething()
Response.Write ("Hello World!")
End Sub
</script>
<%
DoSomething()
%>
VB
|
- ASP.NET does not support page-render functions.
In ASP, page-render functions could be declared with <% %> blocks:
<% Sub RenderSomething() %>
<font color="red"> Here is the time: <%=Now %> </font>
<% End Sub %>
<%
RenderSomething
RenderSomething
%>
In ASP.NET, this must be rewritten:
<script language="VB" runat=server>
Sub RenderSomething()
Response.Write("<font color=red> ")
Response.Write("Here is the time: " & Now)
End Sub
</script>
<%
RenderSomething()
RenderSomething()
%>
VB
|
- With three exceptions, ASP.NET is 100% API-compatible with traditional ASP. The API changes are that, now,
Request(), Request.QueryString(), and Request.Form() all return individual strings, rather than string arrays.
- ASP.NET pages support only a single language.
- ASP.NET page functions must be declared in <script runat=server> blocks.
- Page-render functions are not supported.
Copyright 2001 Microsoft Corporation. All rights reserved.