JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Running a Web Application

Now we've written our first Web application, called First. You run it as you would a Windows application—for example, you can use the Debug|Start menu item in the Visual Basic IDE. Doing so starts the application—but this time, it'll appear not in a standard window, but in your default browser, as you see in Figure 14.7.

Click To expand
Figure 14.7: Running a Web application.

Of course, you don't need Visual Basic to run a Web application; you also can start the application simply by using a browser and navigating to its startup ASPX form on the server (that's http://STEVE/Ch14/First/WebForm1.aspx here; if you were running this page on a Web server named, say, starpowder.com, that could be http://www.starpowder.com/Ch14/First/WebForm1.aspx). The server will do the rest.

You can see the new Web application at work in Figure 14.7, looking a lot like a Visual Basic Windows application. Now you can click the button and the message "Welcome to Web programming" appears in the text box, as it should—although note it takes a round trip to the server to make that happen. You can see the results in Figure 14.7.

Now, try clicking an item in the list box. When you do, nothing happens. Why? I included a list box in this example to show that not all Web server control events are automatically sent back to the server when they occur (to save time by avoiding trips to the server). Click events usually are sent back to the server for processing, but not an event such as a list box's SelectedIndexChanged event.

Events like SelectedIndexChanged are handled the next time the page is sent back to the server. If you were to change the selection in the list box and then click the Click Me button, that would send the form's data back to the server, and when it reappeared, the message "Welcome to Web programming" would appear in the top text box—but the code for the SelectedIndexChanged event also would have run, so the bottom text box would indicate which item you selected.

Sometimes, you don't want to wait until the form is sent back to the server by other events before handling events like the SelectedIndexChanged event. It turns out that you can force events like SelectedIndexChanged to be handled on the server at the time they occur if you set the control's AutoPostBack property to True. To see how that works, set the list box's AutoPostBack property to True and run the application again. When you do and when you change the selection in the list box by clicking a new selection, a message like "You selected Item 1" appears in the bottom text box, without your having to wait until some other event sends the form back to the server. You can see this in Figure 14.8.

Click To expand
Figure 14.8: Enabling a Web application after AutoPostBack.

And that's it—pretty cool, huh? To close the application, you close the Web browser, or select the Debug|Stop Debugging menu item.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor