Page #50 (Chapter 6 - WebClass Debugging and Error Handling)

Chapter 6 - WebClass Debugging and Error Handling

Visual Basic Developers Guide to ASP and IIS
A. Russell Jones
  Copyright 1999 SYBEX Inc.

Debugging Client-Side Script
Stepping through code with the debugger can teach you a tremendous amount about the way VB and WebClasses work. In the Web environment, though, code isn't limited to the server. You're perfectly free to write code that runs on the client as well. Because this book isn't about scripting code for browsers, I'm not going to discuss the code in any depth. Nonetheless, I can't leave the topic of the debugger without pointing out that if you have the right combination of hardware and software (and I realize that's a big if in the Web world), you can extend your debugging session into the browser itself.
To debug client-side script, you must first use the IIS administration program to create an IIS application, then configure the application for client-side debugging.
To do that, open the IIS administration program, find the virtual Web for the WebClassDebug site, right-click it, and select Properties. You'll see the dialog box in Figure 6.4.
  Note Client-side debugging works only with Internet Explorer 4 and higher, so if you're running Netscape or another browser, go out and get a real…(just kidding)…you can skip the rest of this section. It also works only if you have Internet Information Server or Personal Web Server version 4 or higher.
Click the Create button in the Application Settings section of the dialog. The Name field will become active. Type WebClassDebug in the Name field and then click the Apply button at the bottom of the dialog box.
Next, click the Configuration button in the Application Settings section. You will then see the Application Configuration dialog. Click the App Debugging tab, then check the check box labeled Enable ASP Client-Side Script Debugging (see Figure 6.5). Click the Apply button and then click OK until you've closed all the dialogs.
Now you need to write some client-side script so you can debug it. One of the hardest things for people first programming in the ASP/  WebClass/browser environment to understand is that on the server, client-side script is text. It's sent to the browser just like any other text. After it reaches the browser, though, it's code. The two environments are completely separate—the server code knows nothing about the browser code and the browser code knows nothing about the server code. There's no automatic method to share variable values between client-side script and server-side programs. You can't set a server variable directly from client-side script. At any rate, you write client-side scripts with the Response .Write method just as you do with all other text and HTML.
In the WebClass_BeginRequest event, enter the code to write the client-side script.
With Response
    .Write "Entered BeginRequest<br>"
    .Write "<script language=""vbscript"">"
    .Write "    sub onButtonClick()"
    .Write "        msgbox " & Chr(34) & _
      "Your session ID is:" & Session.SessionID & _
      Chr(34) & ", vbInformation + vbExclamation, " _
& """How Did The Browser Know?"""
    .Write "    end sub"
    .Write "</script>"
    .Write "<input type=""button"" value=""Click Me""" & _
      "onClick=""onButtonclick()""><p>"
End With
Save and run the project. When you click the Click Me button, the browser displays a message box containing your current SessionID. Note that you can set client-side variables explicitly with server-side code, but not the reverse.
With Visual Interdev, you can set breakpoints in client-side script, but from within VB, you'll need to introduce an error to view the debugger.
Switch back to the project, press Ctrl+Break to enter break mode, and change the word msgbox in the script to msgBx. Press F5 to switch back into run mode, press Alt+Tab to move back to the browser, and press F5 to refresh the page. This time when you click the button, you'll get an error, and IE will ask whether you want to debug. Click the Yes option.
If IE does not ask whether you want to debug, make sure you haven't disabled debugging within the browser. To check, click the View menu Internet Options Advanced tab (see Figure 6.6).
If IE does ask whether you want to debug, but the debugger doesn't appear, make sure you have the latest version of VBScript and JScript. You can download the latest versions free from Microsoft at http://msdn.microsoft.com/scripting/default.htm.



Visual Basic Developer[ap]s Guide to ASP and IIS
Visual Basic Developer[ap]s Guide to ASP and IIS
ISBN: 782125573
EAN: N/A
Year: 2005
Pages: 98

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