ASP. NET limit: page navigation)

Source: Internet
Author: User

Rob Howard

When I was a child, I spent a few weeks every year in my family. As a young American boy, I was very fascinated by Dutch electric trains, something I had never seen in my hometown of Dallas, Texas. My cousin entertained me by taking their boat to see the train passing. Sitting on the water close to the rail, you can hear the approaching train. It is like a gentle whistle passing through the rail until the train calls and plays a slow climax. This reminds me of ASP. NET 2.0. ASP. NET 2.0 is very close, and most of us are eager to expect its release to arrive early. We even heard the sound of continuous Publishing. At that time, the way we write the software will change.

Microsoft ASP. NET 2.0 aims to provide developers with 50% performance. However, the actual efficiency improvement seems to exceed expectations. The new personalization, membership and role management features take away the developer's burden, while other features, such as data binding, are also simplified. For example, the syntax we are familiar with and are still supported:

<% # Databinder. eval (container. dataitem, "firstname") %>

In ASP. NET 2.0, it can be simplified:

<% # Eval ("firstname") %>

There are not only a large number of new features, but also a large number of meaningful server controls. The ASP. NET programming model becomes more powerful in ASP. NET 2.0 because the server controls are like the <asp: Login> controls that integrate membership and the new data source and data control server controls.

In ASP. NET 2.0, the number of system. Web class libraries almost doubles-overwrite and even require Magazine Column serialization. To really understand the extent of these changes, you need a new ASP. NET 2.0 book. I plan to write some columns here to highlight some important new ASP. NET 2.0 features. In this monthly, I will focus on navigation and Page Flows, starting with the features people are looking for-submitting them to other page capabilities.

Cross-page delivery

I migrate from ASP. NET developers complain most about the page's sending-back model, Asp. NET page can have a single <form> and can only send HTTP back to itself, so that all the processing logic will run in this page.

Many developers, especially those familiar with ASP, prefer to control <form> elements, you will understand where and how to send <form> content data to be submitted (http post or http get) in ASP, and the number of <form> on the same page. However, compared with ASP, ASP. NET only allows one <form runat = Server> page, and can only be sent back to itself. This may be annoying. The following is an example of a page sent to other pages in ASP. net2.0:

<% @ Page masterpagefile = "~ /Site. Master "Language =" C # "codefile =" source. aspx. cs "inherits =" Source "%>
<Asp: Content ID = "maincontent" contentplaceholderid = "Main" runat = "server"> enter your name: <asp: textbox id = "namebox" runat = "server"> </ASP: textbox> <asp: button id = "button1" runat = "server" text = "Submit"/> </ASP: content>

Master pages is used to control the page layout, with a <asp: content> block and some server controls to accept user input.

If you want to pass the content to another page, you can use a server similar to the followingCode:

Response. Redirect ("target. aspx? Name = "+ httputility. urlencode (namebox. Text ));

The problem with this technology is that after the user clicks the button to submit, the server accepts the request and sends a response to turn the browser to taget. aspx. This simple problem has done a lot of work!

Can I simplify my work? In ASP. NET 2.0, the answer is yes. Next we will demonstrate the improved code:

<% @ Page masterpagefile = "~ /Site. Master "Language =" C # "codefile =" source. aspx. cs "inherits =" Source "%>
<Asp: Content ID = "maincontent" contentplaceholderid = "Main" runat = "server"> enter your name: <asp: textbox id = "namebox" runat = "server"> </ASP: textbox> <asp: button id = "button1" runat = "server" text = "Submit" postbackurl = "~ /Target. aspx "/> </ASP: content>

Note the postbackurl attribute in <asp: button>. This attribute notifies the button to directly submit data to target. aspx instead of sending back by default.

You may want to know how this works, especially when you are familiar with ASP. NET viewstate objects. However, this is beyond the scope of this article. When the cross-page delivery feature is used, the page will add a hidden domain:

<Input type = "hidden" name = "_ previouspage" id = "_ previouspage" value = "p1-dFHlCpgH2alr1vkr3G21UIR7jOuzn074led6lbGf1KQ47_F25GwG0"/>

It is a bit like the view status generated by the Control tree, but it is a fragment for cross-page shipping to verify the view status of this page. As you know, when a page is shipped across pages to another page, the receiving page must be accessible to the shipping page instance. In this example, target. asp can access the details of source. aspx. In fact, a more effective method is to access the API from source. aspx to target. aspx through the strongly typed manager. To access the shipping page (the previous page), ASP. net2.0 provides a special page attribute for cross-page shipping: previouspage.

Previouspage returns an instance of the shipping page. Another attribute is used to check whether it is a cross-page shipping: iscrosspagepostback. This attribute is similar to the existing ispostback, but returns true only when cross-page delivery occurs.

The previouspage attribute can have different behaviors. By default, only the instance of the previous page is returned as the page type. However, by using a new instruction, you can let the previouspage attribute return a strong instance, to access the public members of the page. For example, add the following code to target. aspx:

<% @ Previouspagetype virtualpath = "~ /Source. aspx "%>

Now you can use the previouspage attribute on target. aspx to access the data of source. aspx. However, to access the server control, such as the namebox on source. aspx, you also need to write the following code:

Textbox namebox = previouspage. findcontrol ("namebox") as textbox;

In other words, you must use findcontrol to access the control tree. Why? By default, the server control acts as a protected member variable. To truly access the elements of the previous page, you need to set source. the attribute or method on aspx is exposed as public, and the following code can work: textbox namebox = previouspage. namebox;

Cross-page delivery is a great feature of ASP. NET, with someArticleI have discussed in depth the technical details of cross-page delivery. If you are interested in how cross-page delivery works, you can view the cutting edge column published by Dino Esposito IN THE September issue of msdn magazine (see my translation: Asp. net form (translation )). You may also find that if you are proficient in ASP. NET, you will continue to use the standard page re-sending model most of the time. (TRANSLATOR: in other words, if you are a master, you will find yourself stuck with this feature)

Wizard Control

Cross-page delivery makes it easy for ApplicationsProgramBuild a complex navigation function. However, this feature cannot simplify the creation of wizard-style user interfaces. In order to complete the task, wizard-style user interfaces are often designed, regardless of line or non-line. It provides end users with a friendly way to complete a series of complex steps, each step is broken into many blocks.

In ASP. NET 1.x, the Wizard is usually implemented through some techniques: Multiple <asp: Panel> server controls are placed on the same page, and visibility is switched through the user's location. Compiling a wizard in ASP. NET is not easy. Many designers discard the wizard and the management of the process is also messy.

The new cross-page shipping capability in ASP. NET can be used to solve the wizard problem, but it is also a challenge when non-linear navigation is required. For example, step 1, step 2, skip step 3-5, step 6, step 3, step 2, step 6, ASP. NET 2.0 wizard control solves most of these problems. In addition, you can replace all the input elements of the Cross-page shipping wizard with the page sending-back model for continuous access.

The wizard control function is very close to how the Panel is hidden in ASP. NET 1.1. However, the wizard control exposes a series of <asp: wizardstep> that can contain any number of child controls. However, each <asp: wizardstep> must have its own unique ID, as shown in figure 1. The wizard control page manages all the navigation, supports linear and non-linear navigation, and supports complete vs design. Figure 2 demonstrates the wizard control, with Link-Based Nonlinear navigation on the left and linear button navigation on the lower right. From the Open Task menu, you can see that it is not just a public task, but a list of steps that allow switching steps at design time.

 


Figure 2 How the wizard works in Visual Studio

 

All visible elements of the wizard control can be configured. Non-linear links can be replaced by buttons or deletion entries. In the previous step and next step, the linear navigation elements can also be changed to image buttons or links. In fact, all the features of the control can be configured through the template.

One difficulty in compiling wizard controls in ASP. NET 1.1 is to manage the user's location. The wizard control simplifies this work by revealing the activestep property. The activestep attribute can be used to query and determine which step is activated. The wizard's natural process will follow the declared implementation method, and the process can be changed at any time through the moveTo method. With moveTo, any step can be set to activestep. Several events are provided to assist navigation and flow, as shown in figure 3.

The new wizard control is very useful when collecting user information. You do not want to write all the basic structures in ASP. NET 1.1. ASP. NET has prepared all the work for you. The wizard control is very useful. The ast.net group uses it as the base class of the createuserwizard control. The createuserwizard control is used as part of the membership function to create users.

Section

The cross-page shipping and <asp: Wizard> controls provide several new options for ASP. NET developers to control the navigation process in their applications. Cross-page shipping is useful for the current use of response. Redirect or server. Transfer. The wizard control is used to build complex data collection that requires both linear and non-linear data.

Next time, I will analyze the URL rewriting of sitemap in ASP. NET 2.0. Please send questions and suggestions to xtrmasp@microsoft.com.

Author Profile

Rob Howard is the founder of telligent systems and specializes in high-performance Web applications, knowledge base management, and collaboration systems. Rob was previously employed by Microsoft, where he helped design the infrastructure of ASP. NET 1.0, 1.1, and 2.0. To contact Rob, visit rhoward@telligentsystems.com.

Go to the original English page

Figure 1 Wizard steps

<Asp: Wizard runat = "server"> <wizardsteps> <asp: wizardstep id = "Step1"> welcome! </ASP: wizardstep> <asp: wizardstep id = "step2"> what is your name: [textbox1] [button1] </ASP: wizardstep> <asp: wizardstep id = "Step3"> Thank you, [textbox1.text]! </ASP: wizardstep> </wizardsteps> </ASP: Wizard>

Figure 3 Navigation events

Event Description
Activestepchanged Raised when the activestep is set to a new wizardstep
Cancelbuttonclick Raised when the button identified as the cancel button is clicked
Finishbuttonclick Raised when the button identified as the finish button is clicked
Nextbuttonclick Raised when the button identified as the next button is clicked
Previusbuttonclick Raised when the button identified as previous button is clicked
Sidebarbuttonclick Raised when one of the sidebar links or buttons is clicked

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.