Creating a Web Application


In the past, building interactive Web sites was about as easy to understand as the groupies behind PylonOfTheMonth.co.uk, and just as exciting.

However, with .NET comes ASP.NET, the next version of Active Server Pages (ASP). It s a technology that allows even old-hat Visual Basic developers to quickly put together their own intelligent Web sites.

TOP TIP  

Before getting started with any ASP.NET application, you need Internet Information Services 5.0 or above installed on your machine. If you don t have it, you can t play the game.

Let s create a small sample site right now.

  1. From the menu in Visual Studio .NET, select File New Project.

  2. Select an ASP.NET Web Application project type, under the Visual Basic Projects folder.

  3. Change the Location box to http://localhost/hello, then click OK. (See Figure 1-4.)

click to expand
Figure 1-4: Creating a new ASP.NET Web application
TOP TIP  

If you get a warning about Internet Explorer being offline or some such, launch Internet Explorer, cancel any attempts to dial up, then click on File and uncheck Work Offline. Tsk, computers, eh?

You should now be looking at a pretty boring, dotted screen, christened WebForm1.aspx. This is the ASPX Web page your users will see.

Look at the left side of your screen. See the toolbox? These are controls you can use on your Web forms, similar to the way you have controls you can use with regular Windows forms. Let s try a couple now.

  1. Drag and drop a Button and TextBox control anywhere on your Web form.

Next, cast your eyes over to the bottom right of your screen. Notice the Properties window? Again, just as you d have with Windows forms, it s here you can change the properties and behavior of objects you re working with.

  1. Change the Text property of your button to Say It To Me! (See Figure 1-5.)

    click to expand
    Figure 1-5: Painting our Web page

To complete our eye exercise regime , raise your blinkers ever so slightly so the Solution Explorer comes into view. These are all the extra files included to support your Web application. (A full listing of what these files do can be found in Appendix II.) For now, we re concerned with only the actual pages, those files ending with an .aspx extension.

Let s put our foot down now for the event you ve all been waiting for. We re getting juicy: we re adding code .

  1. Double-click on your button.

You should be taken to the Code window. This is actually WebForm1.aspx.vb, the code behind your WebForm1.aspx page. Although the code content here may be different from that behind a Windows form, you ll notice that the structure is still pretty much the same.

Here, we have a public class called WebForm1. You can see that it inherits some of its functionality from the System.Web.UI.Page part of the .NET Framework, and that your Button1 and TextBox1 controls have been declared.

Before the End Class here, we also have the Load event listed, ready for you to insert code into ”plus, of course, our button Click event. Let s add code to that now.

  1. Add the following code to respond to your button Click event:

     TextBox1.Text = TextBox1.Text + " Hi Worldies!" 

So, let s recap. Now, when somebody visits our site and clicks on the button, we want to take the Text property of our TextBox control and add Hi Worldies! to the end of it. How will that work in real life? There s only one way to find out.

  1. Press the F5 key to test your application.

  2. Click on your Say It To Me button a few times. (See Figure 1-6.)

    click to expand
    Figure 1-6: Our final Web application, in full IE6 glory

What happens? Try removing the text and clicking again. What if you type something in yourself and then click? Does it remember what you entered?

Also notice how, each time you click, the Web form is being posted back to the server (Internet Information Services, to be precise), your code runs, and fresh HTML results are returned? Where is that code running? Do you understand the concept here? If you have time, try adding a Calendar control to your page, then run your application and try clicking a few dates. Impressed?

We ll be revisiting the grand world of Web site projects in Chapter 3, plus take a smart look at Web services (part of ASP.NET) in Chapter 5.




The Ultimate VB .NET and ASP.NET Code Book
The Ultimate VB .NET and ASP.NET Code Book
ISBN: 1590591062
EAN: 2147483647
Year: 2003
Pages: 76
Authors: Karl Moore

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