Condividi tramite


Visual Basic Concepts

An Introduction to Webclasses

A webclass is a Visual Basic component that resides on a Web server and responds to input from the browser. When you create an IIS application, you create its webclasses using the Webclass Designer. Webclasses typically contain and the code that delivers those webitems to a client.

Note   There is a one-to-one relationship between the Webclass Designer and the webclass. If you want to add additional webclasses to your application, you must add additional designers.

A webclass is associated with one and only one client for its entire life cycle. Visual Basic creates a logical instance of the webclass for each client that accesses it. However, for each client, the webclass is capable of maintaining state between requests.

For More Information   See "State Management in IIS Applications" for more information about maintaining state in a webclass.

Webclasses and .ASP Files

Each webclass in an IIS application has an associated .asp (Active Server Pages) file that Visual Basic generates automatically during the compile or debug process. The .asp file hosts the webclass on the Web server. In addition, it generates the webclass's run-time component when the application is first started and launches the first event in the webclass's life cycle.

The following figure shows the relationship between .asp files, webclasses, and webclass contents.

Relationship Between .asp Files and Webclasses

As shown in this picture, there is a one-to-one relationship between webclasses and .asp files — each webclass has its own ASP. In turn, a webclass can have many webitems associated with it.

The path to the ASP acts as the base URL for the webclass and its webitems. A URL is a standard way of indicating the location of a document or other item that is available electronically. (For example, https://www.microsoft.com is a URL.) When you want to go to a page on the Web, you enter the URL for the page and the browser retrieves and displays it. You can indicate the URL directly, by typing it into the location line of your browser, or indirectly, by selecting a link that tells the browser the correct URL to which it should go. A base URL refers to the webclass itself, and can act as an entry point into the application.

For example, suppose you have a project called Project 1, that contains a webclass called CustomerInquiry. You specify in the NameInURL property that the ASP should be named Project1_CustomerInquiry. Visual Basic creates the ASP and gives it this name when you compile the project, and stores it in the specified directory, called CustomerSupport, on the Web server you specify:  www.mycompany-inc-10.com. The for your webclass would be the following:

http://www.mycompany-inc-10.com/CustomerSupport/
   Project1_CustomerInquiry.asp

To start your IIS application, the user accesses this URL with their browser.

Webclass Contents: Templates and Custom Webitems

A webclass typically contains webitems that it uses to provide content to the browser and expose events. A webitem can be one of two things:

  • An HTML template file — HTML template files are HTML pages that you associate with your webclass. When the webclass receives a request, it can send the HTML pages to the browser for display. Templates differ from regular HTML pages only in that they often contain replacement areas the webclass can process before sending the page to the browser. This allows you to customize your response.

  • A custom webitem — Custom webitems do not have an associated HTML page they can return to the user. Instead, a custom webitem is a programmatic resource that consists of one or more event handlers that are logically grouped together to help organize your Web application. These event handlers are called from the browser, either when the page loads or when a user selects an HTML element. The event handlers can generate a response to the browser or pass processing to another of the webclass's webitems.

Templates and custom webitems both expose events that the webclass processes when certain actions occur in the browser. You can write event procedures for these events using standard Visual Basic code, thus linking the actions that occur on a Web page to Visual Basic processing.

Each webclass can contain multiple templates and webitems. In most cases, you will need only one webclass in your application, but you might want to use multiple webclasses if you want to break up your application into parts that can be reused in other applications.

For More Information   See "Webclass Events" for more information on template and custom webitem events. See "Adding HTML Templates to the Webclass" for more information on template webitems. See "Adding Custom WebItems to a Webclass" for more information on custom webitems.

IIS Applications vs. Traditional Visual Basic Applications

IIS applications are structured differently than standard, forms-based Visual Basic applications. In an IIS application, the user interface consists of a series of HTML pages rather than traditional Visual Basic forms. An HTML page is like a form in that it contains all the visual elements that make up your application's user interface. You can place some of the same items into a page as you do a form, including text, buttons, check boxes, and option buttons.

An HTML page referenced in an IIS application is saved to an .htm or .html file that is analogous to a .frm file, in that it is used to render and display the page to the end user. Visual Basic creates the .htm file from the original HTML page when you save or debug your application, or when you use the Edit HTML Template menu command.

In an IIS application, you do not use Visual Basic to create the HTML pages that make up the application's user interface. A Web designer or a developer creates the pages using an HTML editor, a word processing package, or a text editor, and you link the finished pages into your webclass.

The following table sums up the differences between forms-based applications and Web-based applications:

  Forms-based application Web-based
application
User interface Visual Basic forms HTML pages
UI elements (for example, text boxes, buttons, images) Controls Elements
File format .frm files .htm files
Creator Developer Web designer with a developer, or the developer alone
Run time Visual Basic run time Web browser

Structure of IIS Applications

An IIS application consists of the following pieces. Many of these are generated for you automatically when you build your project. The pieces include:

  • One or more , which are generated automatically when you create a webclass project.

  • One or more and their events.

  • One or more custom webitems and their events.

    Note   A webclass may contains a mixture of templates and custom webitems, only templates, or only custom webitems. You do not necessarily have to have both templates and custom webitems in your webclasses.

  • An .asp (Active Server Pages) file used to host the webclass in Internet Information Server (IIS). The .asp is generated automatically when you create a webclass project, and given the name you specify in the NameInURL property.

  • A webclass run-time component, MSWCRUN.DLL, that helps process requests.

  • A project DLL (generated automatically on compile) that contains your Visual Basic code and is accessed by the run-time component.

The following figure shows how the server portions of an IIS application work together:

Structure of IIS Applications

Like other Visual Basic applications, an IIS application has code modules and a visual designer. IIS application objects are stored in plain text files that contain the source code of the webclass, events and property settings, and the webitems for the webclass. Visual Basic uses the extension .dsr for these files. In addition to the .dsr file, Visual Basic generates a .dsx file that contains a binary version of the application.