Transfer objects between pages

Source: Internet
Author: User

In fact, this question is not very good. The transferred object can also be a single value.

Simple transfer can be done with a general get or post, and the session can be the same.

Session is easy to use, but it has an impact on the server load.

I personally don't use sessions unless I have.

The following method is widely used on the Internet. I don't know who the original is. I have seen all the traditional simplified versions.

However, it is completely unrecognizable. The following is the main code (not changed). I mainly add some important content, but the original text is not highlighted.

Or there is no such thing. As follows:

Use server. Transfer
  
This method is a little more complex than the method described above, but it is particularly useful in inter-page value transfer, using this method, you can access the exposed value in the form of Object Attributes on another page. Of course, this method is used, you need to write additional code to create some attributes so that you can access it on another page. However, the benefits of this method are also obvious. In general, this method is concise and object-oriented. The entire process of using this method is as follows:
  
1. Add necessary controls to the page.
2. Create the get attribute process of the returned value
3. Create buttons and link buttons that can return the form
4. click the button to transfer the server. Transfer Method to the specified page.
5. On the second page, we can use context. the handler property is used to obtain the reference of the previous page instance object. With it, you can access the value of the control on the previous page.
  
The following code comprehensively implements the above steps:
Source Page code:
Add the following code to the page
Public string name
{
Get
{
Return textbox1.text;
}
}
  
Public String email
{
Get
{
Return textbox2.text;
}
}
Then call the server. Transfer Method
Private void button#click
(Object sender, system. eventargs E)
{
Server. Transfer ("anotherwebform. aspx ");
}
Target Page code:
Private void page_load
(Object sender, system. eventargs E)
{
// Create instance of source web form
Webform1 WF1;
// Get reference to current handler instance
WF1 = (webform1) Context. Handler;
Label1.text = wf1.name;
Label2.text = wf1.email;
}

 

In fact, the above has been explained very well. If you do it, you cannot run it,

An error occurs in "webform1" because the webform1 class cannot be defined at all.

Therefore, add <% @ reference page = "~ /Webform1.aspx "%>

You can run it.

OK, so that all methods and attributes of the source page can be completely called.

This method is cool !!!!!!!!!!!!

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.