Need to Know More?
|
Chapter 4. Implementing Navigation for the User InterfaceTerms you'll need to understand:
Techniques you'll need to master:
This chapter discusses various state management features
provided by ASP.NET, including client-side techniques and
server-side techniques. This chapter also discusses the ASP.NET
intrinsic objects available via the
Page
class. Finally,
this chapter
|
Round Trip and Postback
A Web application has a distributed execution model. When a
Step 3 is referred to as a page postback , whereas steps 3 and 4 are collectively referred to as a round trip . A round trip involves making a complete trip over the network to the Web server and getting the response back.
The Web applications use Hypertext Transmission Protocol (HTTP)
to establish communication between the Web browser and Web server.
HTTP is
disconnected
in nature, which means the life
cycle of a Web page is just a single round trip. Between two page
requests, the Web server and the
This model of execution enables a Web server to support a large number of clients because each client request occupies the server resources only for a short duration. However, the disconnected nature of HTTP provides a major challenge to Web developers, who must implement the following functionality in their applications:
ASP.NET provides solutions to these problems built into the programming framework. From the discussion about server controls in Chapter 3, "Controls," you already know that server controls automatically retain their values across page postbacks. You will learn how ASP.NET actually retains the states for server controls later in this chapter in the section titled "State Management." For now, I'll talk about two properties of the Page class IsPostBack and SmartNavigation that provide the other two functionalities from the previous list. The IsPostBack PropertyThe IsPostBack property of the Page class returns true when a page is being loaded in response to a client postback. If the page is being requested for the first time, the value of the IsPostBack property is false . A typical case in which you would use this distinction is when you do not want the server to execute costly initialization operations for each page postback. Instead, the initializations are to be performed only with the first request to the page.
The following example helps you understand round trip and
postback operations and
The previous example uses the event handler for the
Load
event of the
Page
class to check whether the
page is loaded by a postback operation. If that is the case,
executing the code for adding items to the drop-down list is
Also note that the navigation between controls is not smooth. When the form returns after a postback, it does not remember the active control. However, the SmartNavigation property can solve this problem. The SmartNavigation PropertyASP.NET has a feature called smart navigation that can greatly enhance the user experience of a Web page by
Smart navigation is specified by the SmartNavigation attribute of the Page directive. To enhance the Web form created in the previous example to use the smart navigation feature, you need to modify its Page directive to the following:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="Example4_1.WebForm1"
SmartNavigation="true"
%>
Smart navigation is very useful for intranet applications where
you have more control over the browsers used by the users. For such
applications, you might want to
<configuration>
<system.web>
<pages smartNavigation="true"/>
</system.web>
</configuration>
|