Multi-Browser Support and Validation

   

This is an area that could afford some investigation on how ASP.NET delivers different code to different browsers depending on their capabilities. As I've said, ASP.NET is pretty smart about handling browser capabilities and rendering code that different browsers can handle.

By default, ASP.NET lumps browsers together as uplevel and downlevel browsers.

  • Uplevel. Internet Explorer 4.x and up

  • Downlevel. Basically everything else, including Netscape 6.x

These aren't hard and fast rules for all Web server controls, but where validators are concerned, the uplevel browsers deliver both JavaScript client-side validation and server-side validation, and downlevel browsers are restricted to server-side validation. Take a look at the code generated for CompareValidator in both an uplevel and downlevel browser.

Uplevel Browser
<html>  <head>  <title>Validators - Compare</title>  </head>  <body bgcolor="#FFFFFF" text="#000000">  <form name="_ctl0" method="post" action="web_comparevalidator_vb.aspx"  graphics/ccc.giflanguage="javascript" onsubmit="ValidatorOnSubmit();" >  <input type="hidden" name="__VIEWSTATE"  graphics/ccc.gifvalue="dDwtMTI1OTcyOTYwNzs7Pv8j9BzKw7eb4mzYMNwlwPYrQl1R" />  <script language="javascript" src="/books/1/582/1/html/2//aspnet_client/system_web/1_0_3705_0/WebUIValidation. graphics/ccc.gifjs"></script>  <h3>Set Up User Account</h3>  Username: <input name="UserName" type="text"  /><br>  Password: <input name="Password" type="password"  /><br>  Confirm: &nbsp;&nbsp;&nbsp;<input name="PasswordConfirm" type="password"  graphics/ccc.gif /><br>  <span  controltovalidate="PasswordConfirm" errormessage="Hey, They  graphics/ccc.gifdon't Match"  evaluationfunction="CompareValidatorEvaluateIsValid" controltocompare="Password"  graphics/ccc.gifcontrolhookup="Password" style="color:Red;visibility:hidden;">Hey, They don't Match</ graphics/ccc.gifspan><br>  <input type="submit" name="_ctl1" value="Submit" onclick="if (typeof(Page_ClientValidate)  graphics/ccc.gif== 'function') Page_ClientValidate(); " language="javascript" /><br>  <script language="javascript">  <!       var Page_Validators =  new Array(document.all["ComparePasswords"]);  //  >  </script>  <script language="javascript">  <!   var Page_ValidationActive = false;  if (typeof(clientInformation) != "undefined" && clientInformation.appName.indexOf( graphics/ccc.gif"Explorer") != -1) {     if (typeof(Page_ValidationVer) == "undefined")          alert("Unable to find script library '/aspnet_client/system_web/1_0_3705_0/ graphics/ccc.gifWebUIValidation.js'. Try placing this file manually, or reinstall by running  graphics/ccc.gif'aspnet_regiis -c'.");      else if (Page_ValidationVer != "125")          alert("This page uses an incorrect version of WebUIValidation.js. The page  graphics/ccc.gifexpects version 125. The script library is " + Page_ValidationVer + ".");      else          ValidatorOnLoad();  }  function ValidatorOnSubmit() {     if (Page_ValidationActive) {         ValidatorCommonOnSubmit();      }  }  //  >  </script>  </form>  </body>  </html> 
Downlevel Browser
<html>  <head>  <title>Validators - Compare</title>  </head>  <body bgcolor="#FFFFFF" text="#000000">  <form name="_ctl0" method="post" action="web_comparevalidator_vb.aspx" >  <input type="hidden" name="__VIEWSTATE"  graphics/ccc.gifvalue="dDwtMTI1OTcyOTYwNzs7Pv8j9BzKw7eb4mzYMNwlwPYrQl1R" />  <h3>Set Up User Account</h3>  Username: <input name="UserName" type="text"  /><br>  Password: <input name="Password" type="password"  /><br>  Confirm: &nbsp;&nbsp;&nbsp;<input name="PasswordConfirm" type="password"  graphics/ccc.gif /><br>  &nbsp;<br>  <input type="submit" name="_ctl1" value="Submit" onclick="if (typeof(Page_ClientValidate)  graphics/ccc.gif== 'function') Page_ClientValidate(); " language="javascript" /><br>  </form>  </body>  </html> 

The downlevel code block doesn't have the weight of the JavaScript, but remember that it must make a round trip to the server to validate the data, whereas the uplevel browser can handle client-side validation.

To investigate more about the function of ASP.NET and browser capabilities, check out the following URL for the .NET Framework SDK. It will supply you with a lot of information on how ASP.NET handles browsers and how you can manipulate what code is delivered to the browser through the HTTPBrowserCapabilites object.

ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpconWebFormsControlsBrowserCapabilities.htm


   
Top


ASP. NET for Web Designers
ASP.NET for Web Designers
ISBN: 073571262X
EAN: 2147483647
Year: 2005
Pages: 94
Authors: Peter Ladka

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