ASP.NET Supports Web Services - Examining the Code-behind feature
(Page 3 of 5 )
Separating business logic from the presentation layer receives support from the runtime by providing the new code-behind feature. You begin by deriving from the Page class. Then place your code in an .aspx file and insert a reference to another file containing the business logic just as demonstrated below:
<%@ Page Language="vb"%>
<%@ Register TagPrefix="ASPBtn" TagName="ClientName" Src="RegisterClient" %>
The following code example contains HTML, text, and several lines of VB .NET code. The Web form has two textbox controls named FirstName and LastName. The form also has two RequiredFieldValidator controls that prevent you from submitting the form to the server without entering data in the FirstName and LastName Textbox controls.
Note: the <asp: TextBox tag informs the compiler that this ASP.NET page contains a text box control for execution on the server. A typical ASP.NET page looks like this:
<%@ Page Language = "vb" AutoEventWireup="false" Codebehind = "WebForm1.aspx.vb" Inherits="IFCE.WebForm1"%>
<html><head><title>Registering a new client</title></head>
<body>
<form runat="Server">
<p>FirstName:
<br><asp:TextBox id="firstName" runat="Server"/>
<asp:RequiredFieldValidator ControlToValidate="firstName"
Runat="Server"/>
<p>LastName:
<br><asp:TextBox id="lastname" runat="Server"/>
<asp:RequiredFieldValidator
ControlToValidate="lastname"
Runat="Server"/>
<p>
<asp:button text="Submit Form" Runat="server"/>
</form>
</body>
</html>
Notice: If the <form> element is not present on the page, both web controls and HTML controls will not be able to participate in page post backs, nor will they be able to save their state in the page’s ViewState. They will continue to function otherwise.
It is important to utilize one of the key benefits ASP.NET offers, namely preserving state between client page requests. Always add the <form> element to the Web Forms page. If a post back event occurs, any state stored in hidden fields rendered to the form is retrieved and sent back to the server for rendering the new page to the browser. The user views the newly rendered .aspx page as though it were the original page. In reality, they are two individually unique pages.
Next: Examining the ASP.NET Page Class Process >>
More ASP.NET Articles
More By Dwight Peltzer