Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 17

Sending HTML Text Directly to the Client

When you add a WebClass designer to an IIS project (either as the first default WebClass or as a WebClass that you add from the Project menu), VB automatically puts some default code in the WebClass’ Start event procedure, as shown in Listing 17.3.

LISTING 17.3
DEFAULT START EVENT PROCEDURE CODE IN A NEW WEBCLASS DESIGNER

Private Sub WebClass_Start()
‘Write a reply to the user
With Response
.Write "<html>"
.Write "<body>"
.Write "<h1><font face=""Arial"">WebClass1’s Starting
Page</font></h1>"
.Write "<p>This response was created in the Start
event of WebClass1.</p>"
.Write "</body>"
.Write "</html>"
End With
End Sub

The WebClass’ Start event, as you might imagine, runs the first time that an end user initiates a copy of your WebClass by navigating to the host ASP page.

Note that the default code in the Start event calls the Write method of the Response object. The Response object is in charge of sending information back to the browser. The information to be sent will be HTML code that the browser will then see as a Web page.

To examine the appearance of the unmodified default page sent back by the WebClass, just run your project as soon as you have created it. The first time that you run a WebClass project, you will see the Debugging tab of the Project Properties dialog box as shown in Figure 17.2. Normally, you will leave the default options as they are (that is, run the component using the default browser), and just click the OK button.

After you have passed beyond the Save dialog box for the project’s files, your browser (typically, Internet Explorer when you develop with Visual Studio) will display the page created by the calls to Response.Write in the WebClass’ Start event procedure, as shown in Figure 17.3.

Note that the Browser’s Address box (indicating the URL of the current page) points to an ASP file with the same name as your WebClass. VB automatically generated the ASP file when you ran the project in the IDE. As mentioned previously, the function of the ASP is to host the WebClass object that you are programming. The ASP file will be distributed with your project when you use Package and Deployment Wizard to create a setup package. You will not want to modify the ASP file, because VB would only overwrite it the next time that you try to run your application from the VB environment or distribute it with Package and Deployment Wizard.

If you choose the View, Source option from IE’s menu, you will see the HTML code that your browser received, as shown in Listing 17.4.

LISTING 17.4
HTML SOURCE CODE SENT TO THE BROWSER BY THE DEFAULT START EVENT PROCEDURE’S CODE IN WEBCLASS1

<html><body><h1><font face="Arial">WebClass1’s Starting Page</font></h1><p>This response was created in the Start event of WebClass1.</p></body></html>

You are seeing the HTML that the Start event procedure of the WebClass generated with calls to Response.Write. Microsoft’s idea in providing you with the default code in the Start event procedure is that you can modify the default calls to Response.Write to suit your own purposes, as shown in Listing 17.5.

LISTING 17.5
CUSTOMIZED START EVENT PROCEDURE OF A WEBCLASS

Private Sub WebClass_Start()
‘Write a reply to the user
With Response
.Write "<html>"
.Write "<body>"
.Write "Page accessed at: " & Format(Now, "hh:mm")
.Write "<h1><font face=""Arial"">Order Entry
system</font></h1>"
.Write "<p>Make your initial selection from the list.</p>"
.Write "</body>"
.Write "</html>"
End With
End Sub

Of course, such simple modifications as shown in Listing 17.5, no matter how many lines of pure HTML code they might include, would not take full advantage of an IIS application’s capabilities. You might as well just create an HTML page or an ASP page with a text editor or Web authoring tool.

You can use VB’s more advanced processing and logic to create dynamic HTML code (as illustrated in the line that includes the current time in Listing 17.5).

To take full advantage of the IIS application’s possibilities, however, you will want to avail yourself of two more advanced IIS application features:

  • The capability to associate an HTML template with each WebClass object.

  • The capability to use WebItems to define and process custom events associated with the HTML code for a WebClass. The following sections discuss these techniques.

The following sections discuss these techniques.

Programming With an HTML Template


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved