Online Everyday, I asked how to pass the value between the WebForm page. Basically, everyone is familiar with (1) URL string (2) session pass value (3) directly read data on the page of Server.Transfer In the front, I don't say it. Everyone knows how to use it, and there may be fewer people who may use it, and let's introduce it. The web form page is a class in the application, so you can create properties to handle any classes. However, because the web form page is actually existed during the execution page, their life cycle is very short. Therefore, the use of the web form page is quite limited because they exist only during the process of processing the page. However, if you use specific technologies to pass the control from one page to another, you can still access the properties on the previous page. For example, on a webform page (Page.aspx) placed a label, in Private Void Page_Load (Object Sender, System.EventAnTargs E) {this.label1.text = "Test";} We set its value, Then set a public property public lab {get {return label1;}}, which is returned to this page class is the next Label on this page, and add the following code Server to the click Click event of the button. Transfer ("newpage.aspx"); also placed a Label tab in NewPage.aspx, used to display the value of the Label of the previous page, then add the following code if (! Ispostback) {page p = (Page) ) Context.handler; this.label1.text = "The value passed is:" p.Lab.Text;}
We run this program, click the button, and find the value pass, but the browser's URL display is still the original page.aspx, indicating that Server.Transfer does not change the URL of the browser, in fact, this means that this event is just The server is completed and does not go to the client, which is why you can get the data of the data in front of the stateful HTTP, if you change to response.Redirect, you can't get anything. Analyze the above code NewPage P = (newPage) Context.Handler means creating an instance variable of the source page class, and then assigns the HTTP object (an instance of the IhttPHandler class), that is, the initial request. The benefits of such passages are not like the use of memory as SESSION, especially for big data (in fact, this is not called the value), the bad place can only be between the same server page, and the URL does not change, the user will see it Paste. You can further improve the program, we are currently passing a Label instance, you can pass all objects between the page, or you can use the DataGrid of a previous page directly!