9CBS - Document Center - .NET Title between two ASP.NET Pages KWKLOVER (translation) keyword ASP.NET, pass, value transfer http://www.dotnetBips.com/displayArticle.aspx?id= 79
In the two ASP.NET pages, the transmitted value in the presentation ASP.NET provides an excellent event-driven programming model that allows developers to simplify the overall design of the application, but this also causes some problems inherent, for example, using tradition In the ASP, we can easily achieve the value between the page, the same thing, the same thing, the same thing, is not so easy to use the event-driven programming model, of course, there are still some ways to achieve the same Function. This article will try to use different possible methods to solve this problem, but it is foreseeable that this article will contain the value passed using querystring, session variables, and server.transfer methods. Using queryString Using QuerySting The transfer value between the page is already a very old mechanism. The main advantage of this method is very simple, but its disadvantage is that the value passed is displayed on the address bar of the browser. (Insecure), it is not possible to pass objects, but this method is still a good solution if the value is small and the safety requirements are not high. The steps to use this method are as follows: 1. Use the control to create a Web Form (Form) 2. Create a button and link button 3 that can return a form. Create a character variable 4 that saves the URL in the click event of the button or link button. Add queryString parameter 5 in the saved URL 5, use Response.Redirect to redirect the code snippet below to demonstrate how to implement this method: Source page code: Private void button1_click (Object sender, system.eventargs e) {String url; url = "? anotherwebform.aspx name =" TextBox1.Text "& email =" TextBox2.Text; Response.Redirect (url);} target page code: private void Page_Load (object sender, System.EventArgs e) {Label1.text = Request.QueryString ["name"]; label2.text = request.QueryString ["email"];} Using the session variable using the session variable is another way to pass the value between the page, in this In the case, we exist in the value in the control, and then use it in another page to implement values during different pages. However, it should be noted that there are more data in SESSION variables to consume more server resources. When using sessions, it should be cautious, of course, we should also use some cleaning action to remove some unwanted session to reduce resources. Necessary consumption.
The general steps of using the session variable transmission value are as follows: 1. Add the necessary controls in the page, create buttons and link buttons that can return to the form, add the value of the control to the session on the button or link button, add the value of the control to the session Variables 4, use the response.redirect method to redirect to another page 5, extract the value of the session in another page, when you are determined that you don't need to use the session, to explicitly clear it below the code snippet demonstrate how to implement this method : page code source: private void Button1_Click (object sender, System.EventArgs e) {// textbox1 and textbox2 are webform // controls Session [ "name"] = TextBox1.Text; Session [ "email"] = TextBox2.Text; Server.Transfer ("ANOTHERWEBFORM.ASPX");} Target Page Code: Private Void Page_Load (Object Sender, System.EventArgs E) {Label1.Text = Session ["Name"]. ToString (); label2.text = session [ "email"]. toString (); session.remove ("name"); session.remove ("email");} Using Server.Transfer, this method is slightly complicated than the method described above, but passes on page interval It is especially useful, using this method you can access the revealed values in another page, of course, use this method, you need to write some code to create some properties so that you can A page access it, however, the benefits of this way are also obvious. Overall, it is a simple to use this method.