How ASP.NET Works

Basically, ASP.NET w orks by using server-based components to generate HTML. The HTML is sent to the client and rendered in a browser. ASP.NET determines the capabilities of the client browser and generates HTML appropriate for that browser.

ASP.NET works by using server-based components to generate markup, such as HTML, and script. The HTML and script are sent to the client and rendered in a browser. ASP.NET determines the capabilities of the client browser and renders HTML appropriate for that browser. The type of markup sent to the client is determined by the controls. This markup code doesn't have to be HTML; for example, the mobile controls send WML to wireless devices.

ASP.NET user code (for example, the code that set the label text in your first project) is precompiled. This is in contrast to ASP, which interprets the script code that is intermingled with static HTML. Even if you were using compiled COM components with ASP, the calls to the components were late-bound. Using ASP.NET allows you to benefit from all the services of the .NET Framework, such as inheritance, security, and garbage collection.

ASP.NET also provides some of the functionality that has been coded by hand in the past. Like ASP, ASP.NET can provide automatic state management. Because HTTP is a stateless protocol, maintaining state in Web applications has always been a problem. ASP.NET provides state management that, unlike ASP, is scalable across Web farms, survives IIS crashes, and can be used without relying on cookies.

Web Pages and Code

The pages you create are divided into two parts: the user interface and the code. You can see this in the WebAppTest project because you have WebForm1.aspx and a WebForm1.vb. The .vb file is a class file, called a page class, and it segregates your logic code from the HTML. When you create the page in VS .NET, you see the ASPX and the VB files as two views of the same page. When you compile the page through VS .NET, ASP.NET generates a new class and compiles it. This new class has the static HTML, ASP.NET server controls, and code from your form compiled in. Unlike ASP, all the HTML sent to the client is generated from the class on-the-fly. This class is actually an executable program, and whenever the page is called, the executable generates the HTML that is sent to the browser.

In the case of the page you created earlier, a compiled class was created from these two files. When someone browses the ASPX page, the class is executed and generates the HTML to send to the browser. If you look at the HTML sent to the browser, you'll notice that all the controls you added (the label and the button) are inside an HTML <FORM>...</FORM> block. This is because an HTML form is the only way for standard HTML to get data from an HTML page back to the server.

The code you wrote for the click event runs only on the server. When someone clicks the button, it acts as a submit button, which you can also see in the code. So, the user clicks the button, and the form is submitted to the server. In effect, you take the click event and send it to the server for processing. The generated class is instantiated, and the click event code is processed. A new HTML stream is generated and sent back to the client browser. This new HTML stream contains a new string to be placed in the label; in this case, the string is the text Hello, World!. ASP.NET works this way because you added server controls to the page. Server controls are discussed in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.86.215