Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Sunday, February 12, 2006

Enabling Client/Browser Communication with the System.Web Namespace(Chapter 2)

Perhaps one of the most important namespace for ASP.NET, the System.Web namespace contains most of the functionality for building ASP.NET pages.You’ll be covering the classes and functionality of this namespace extensively in later chapters (you’ll have to, in order to learn ASP.NET!), so we’ll only touch on its members here.
Supplied Functionality
Specifically, the System.Web interface provides the functionality that enables client/browser communication, which is key for ASP.NET pages.The System.Web.HttpResponse class encapsulates Hypertext Transfer Protocol (HTTP) response information. Likewise, the System.Web.HttpRequest object encapsulates HTTP values sent from a client. In addition, you now have the HttpServerUtility object, which provides helper methods that parse HTTP information and return server variables.
This namespace also has classes for dealing with many common HTTP related functions: the HttpCookie object lets you create and read cookies; the HttpApplication class provides control over the ASP.NET application itself; HttpCachePolicy is used to set HTTP headers that specify how you can cache ASP.NET pages; and the HttpFileCollection class provides access to files uploaded by clients.There are quite a few other useful classes in this namespace as well— see the .NET Framework SDK Documentation for more information.
System.Web.UI Namespace Set
In the System.Web namespace, the System.Web.UI subnamespace is probably the most used collection of objects in ASP.NET. It provides all the functionality you’ll need to create, render, and display user interface (UI) elements to the end user.
The System.Web.UI.Control object is the base class for almost all of the UI objects you’ll be using in ASP.NET. It provides methods and properties that are common to all ASP.NET server controls, thus making it easy to learn how each control works. Figure 2.3 shows the hierarchy of objects based on this class.
Figure 2.3 The Hierarchy of UI Objects


The System.Web.UI.HtmlControls and System.Web.UI.WebControls subnamespaces provide the classes that render actual UI elements such as HTML input text boxes and forms.You’ll learn more about these in Chapter 3. For example, Figure 2.3 shows the HTMLAnchor object in the System.Web.UI.HtmlControls namespace.The minimum amount of ASP.NET code that would utilize this object is shown in Figure 2.4.
Figure 2.4 Using Objects in the System.Web.UI Namespace
1: <%@ Page Language="VB" %>
2:
3: <html><body>
4: <a href="blah.aspx" runat="server">Click me!</a>
5: </body></html>
This listing simply displays an anchor in the Web page, as shown in Figure 2.5. Notice that it looks just like a regular HTML page with the exception of the @Page and runat=“server” attributes.The runat=“server” tells ASP.NET that this control isn’t just a normal HTML anchor, but rather an instance of the server object HTMLAnchor, which contains properties and methods.You can easily turn most HTML controls into their ASP.NET object counterparts simply by adding the runat=“server” attribute. Using objects from the WebControls namespace is a bit different, but no more difficult. Figure 2.6 shows an example.
Figure 2.5 A Simple HTMLAnchor Control

Figure 2.6 A TextBox Web Control
1: <%@ Page Language="VB" %>
2:
3: <html><body>
4: <asp:TextBox value="Welcome to ASP.NET!" runat="server"/>
5: </body></html>
This syntax is a bit different than normal HTML, but is one that you’ll be seeing very often in ASP.NET pages, as well as later in this book. Again notice the runat=“server” on line 4—this attribute is vital for ASP.NET controls to function correctly.Without it,ASP.NET believes that you are just trying to create a customized tag that it doesn’t recognize, and so it will just send it as is to the browser, which won’t produce the right results. Figure 2.6 produces the result shown in Figure 2.7.
It is necessary to mention a subset of ASP.NET controls that deal with data, as they are very important in ASP.NET: the Repeater, DataList, and DataGrid controls. These controls have no specific counterparts in HTML, but rather present a complex UI consisting of HTML tables and lists.Any time you have a data source, you can simply bind it to these objects (you can actually bind data to any type of ASP.NET controls, but more on that in later chapters) and the object will provide the UI for you, no matter how complex it may be. Figure 2.8 shows an example of the DataGrid in action.
Figure 2.7 An ASP.NET TextBox Control


Figure 2.8 The DataGrid Web Control

The code to generate Figure 2.8 is shown in Figure 2.9.

0 Comments:

Post a Comment

<< Home