JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating a Multiform Web Project

As in Windows applications, you can add multiple forms to a Web application. To see how this works, I'll create a new example here, called Multiform on the CD-ROM. This example will put to work a few Web server controls we'll see in the following chapters, but whose use is very like what we've seen with Windows controls. In the main form, WebForm1, I add a Web server label control with the text "Web Form 1", as you see in Figure 14.12. (Set the Font property of this label to XX-Large.) Next, add two hyperlink controls with the HyperLink tool in the toolbox. Set the text of HyperLink1 to "Web form 2" and the text of HyperLink2 to "See HTML Page 1", as you see in that figure.

Click To expand
Figure 14.12: Starting a multiform Web application.

Now we can add a new Web form to the project—just select the Project|Add Web Form menu item and click Open in the Add New Item dialog box that appears. This adds WebForm2 to the project (just as we might have added Form2 to a Windows project). Besides Web forms, you also can add simple HTML pages to our project. To see how that works, select the Project|Add HTML Page menu item and click Open, creating HTMLPage1 and adding it to our project.

All that's left is to navigate to the new Web form and HTML page when the user clicks the corresponding hyperlink. To connect HyperLink1 to WebForm2, select HyperLink1 and select the ellipsis ("") button in the NavigateURL property in the Properties window to open the Select URL dialog box you see in Figure 14.13. This dialog lists the other files in our project—select WebForm2.aspx and click OK to connect the hyperlink to WebForm2.

Click To expand
Figure 14.13: The Select URL dialog box.

Also, set the NavigateURL property for the second hyperlink, HyperLink1, to HTMLPage1.htm, connecting that hyperlink to the simple HTML page.

Next, you have to set the hyperlinks' target. In HTML, a link's target specifies where the data the hyperlink points to will appear, and that's especially valuable when you're working with HTML frames. If you don't set the hyperlinks' Target properties, WebForm2 and HTMLPage1 will appear in new browser windows when you click them. To make them appear in the same browser window as WebForm1 (so they replace WebForm1 when they appear), set the Target property of each hyperlink to "_self" in the drop-down list that appears in the Properties window for this property ("_self" is the HTML term for the current window).

When you run this example, you see the two hyperlinks, now active, as shown in Figure 14.14.

Click To expand
Figure 14.14: Hyperlinks for navigating to a new form.

When you click a hyperlink, such as the one to WebForm2, that new form appears in the browser as you see in Figure 14.15. (I've added a label like the one in WebForm1 to this form so we can tell what form we're looking at.)

Click To expand
Figure 14.15: Navigating to a new form.

In this way, we're able to support multiple forms in a Web application. (Note that we'll take a closer look at hyperlink and label controls in upcoming chapters.)

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor