Page

9.1.2- Using Objects Correctly

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as 09. Error Handling.

Not tagged.
<< 9.1.1- Isolating the Location of the ErrorChapter99.2.0- Types of Error >>

Using Objects Correctly

Having decided where your script code is executing it's alsoimportant not to do the wrong thing in the wrong place, and knowing where youare means you won't try to use objects that aren't appropriate to your currentlocation. Try using Guatemalan Quetzals to pay for souvenirs of your trip toFrance, and you'll get the idea.

 

What's all this leading to? Well, there are distinct sets ofobjects. Some are server-side objects, such as the Responseobject, and some are client-side, such as the Documentobject.

 

For example, consider this client-side script:

 

<HTML>

 . . . ' some HTML tags

 

<SCRIPT LANGUAGE=VBScript>

Sub Window_onLoad()

  Response.Write "Hello"

End Sub

</SCRIPT>

 

</HTML>

 

Try running that and you'll get the following error:

 

Chapter9_image003.jpg

This is because the Responseobject is only available as part of ASP, that is, in server-side scripting.Thus this is a client-side error, not an ASP error.

 

Likewise, trying this code:

 

<HTML>

<BODY>

<A ID=FieldName>Some text</A>

 

<%

  Dim objField

  Set objField = Document.All("FieldName")

%>

 

</BODY>

</HTML>

 

will give the following error if you scroll down the page:

 

Chapter9_image004.jpg

 

This is because the Documentobject is only available at the client, that is, in the web browser.

Also notice the difference between how the two errormessages are displayed. The first example generated an error on the client, soit popped up an error dialog. The second example generated an error in ASP, sothe error was returned as HTML code, which subsequently made up the web page.ASP, on its own, can't display error dialogs because it runs on the server –any dialog would appear on the screen of the web server, which isn't much goodif you're five thousand miles away. As we're talking about ASP, we're not goingto be paying much attention to client-side errors, but we will be looking atthe difference between client and server debugging a little later.

<< 9.1.1- Isolating the Location of the ErrorChapter99.2.0- Types of Error >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |