Differences in Request , Request.Form , and Request.QueryString


Differences in Request , Request.Form , and Request.QueryString

In ASP Classic, the Request , Request.Form , and Request.QueryString methods return an array of strings. In ASP.NET, all three methods return a single string.

ASP Classic returns an array of strings because multiple items in the Form or QueryString collection might have the same name. For example, the following URL adds two items with the same name to the QueryString collection:

 
 http://www.Superexpert.com/Default.aspx?favColor=blue&favColor=green 

In ASP Classic, if you want to display both values of the favColor query string variable, you need to loop through the string array returned by the QueryString method like this:

 
 <% Dim favColor For each favColor in Request.QueryString( "favColor" )   Response.Write( favColor ) Next %> 

In ASP.NET, the QueryString() method always returns a single string. In this case, the string is blue,green . If you need to return a collection instead of a single string, you need to use the GetValues() method like this:

 
 <% Dim favColor For each favColor in Request.QueryString.GetValues( "favColor" )   Response.Write( favColor ) Next %> 

This same discussion applies to Request.Form . If a form contains a list box that allows multiple items to be selected, the Form collection might contain multiple items with the same name. In ASP Classic, Request.Form() returns a string array, whereas in ASP.NET, Request.Form() always returns a single string.

NOTE

For some odd reason, in ASP Classic, the lower bound of the string array returned by Request.QueryString and Request.Form was 1 . In ASP.NET, the lower bound of the array returned by the GetValues method is .




ASP.NET Unleashed
ASP.NET 4 Unleashed
ISBN: 0672331128
EAN: 2147483647
Year: 2003
Pages: 263

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net