Several methods of passing the values ​​between the ASP.NET page

xiaoxiao2021-03-06  54

Disclaimer: This article is taken from the "Programmer League"

Several methods of passing the values ​​between the ASP.NET page

ASP.NET Web Forms provides developers with an excellent event-driven development mode. However, this simple application development model has brought us some small problems. For example, in traditional ASP applications, you can easily transfer a value or multiple values ​​via the Post method. To another page, use the same method to achieve a bit troubles in ASP.NET. Here, we can solve this situation in other ways. ASP.NET provides us with three ways, one is that the corresponding value can be transmitted by queryString, one is to transmit the corresponding value by the session variable, and is achieved by the Server.Transfer method. The following describes: 1. Use queryStringQueryString is a very simple transmission method, which is that the value to be transmitted is displayed in the address bar of the browser and cannot be passed in this method. If you want to deliver a security is not so important or a simple value, it is best to use this method. By a small example, the steps are completed, the steps are as follows: 1. Create a web form2, placed a button1 in the newly built web form, set two TextBox1, TextBox2 3, create the Click event code for the Button button: Private void Button1_Click (object sender, System.EventArgs e) {string url; url = "webform2.aspx name =?" TextBox1.Text "& email =" TextBox2.Text; Response.Redirect (url);} 4, new a target page named webform25, placed in two Label1 webform2, Label2 WebForm2 add the following code to the Page_Load: private void Page_Load (object sender, System.EventArgs e) {Label1.Text = Request.QueryString [ "name"] Label2.text = request.QueryString ["email"];} Operation, you can see the resulting result. Second, using the session variable using the session variable transmission value is the most common way, this method can not only pass the value to the next page, but also pass to multiple pages until the value of the session variable is removed, Variables will disappear.

转载请注明原文地址:https://www.9cbs.com/read-117102.html

New Post(0)