Re-uploads values between ASP. NET pages

Source: Internet
Author: User

1. Use query string

Note: I used to ignoreServer. urlencode ()AndServer. urldecode ()Remember, remember!

(1) Source Page

1 Protected VoidQuerystringbutton_click (ObjectSender, eventargs E)
2{
3Response. Redirect ("Querystringpage. aspx? Data ="+ Server. urlencode (datatosendtextbox. Text ));
4}

(2) Target page

 1    <  Form  ID  = "Form1" Runat  = "Server"  > 
2 < Div >
3 < H1 > Target page-query string </ H1 >
4 The data already ed from the source page is:<% = Server. urldecode (request. querystring [ " Data " ]) %> < BR /> < BR />
5 </ Div >
7 </ Form >

2. Use session

(1) Source Page

 

1Protected VoidSessionstatebutton_click (ObjectSender, eventargs E)
2{
3Session ["Data"] = Datatosendtextbox. text;
4Response. Redirect ("Sessionstatepage. aspx");
5}

(2) Target page

 

<Div>
<H1> Target page-session state The data already edFromThe Source PageIs: <% = Session ["Data"] %> <Br/>
</Div>
</Form>

3.Use httppost

Note: This is the first time you have seen this usage. Remember this time.

(1) Source Page

 <ASP: buttonID= "Httppostbutton"Runat= "Server"Text= "Use httppost" 
Postbackurl= "~ /Httppostpage. aspx"/> <BR/> <BR/>

(2) Target page

 <  H1  > Target page-httppost </  H1  > 
The data already ed from the source page is: <% = Request. Form [ " Datatosendtextbox " ] %> < BR /> < BR />
< Fieldset >
< Legend > All form data from the sending page </ Legend >
< ASP: Label ID = "Receiveddatalabel" Runat = "Server" Text = "Label" > </ ASP: Label >
</ Fieldset >
< BR />

 

  Protected   Void Page_load ( Object Sender, eventargs E)
{
System. Text. stringbuilder displayvalues =
New System. Text. stringbuilder ();
System. Collections. Specialized. namevaluecollection
Postedvalues = request. form;
String nextkey;
For ( Int I = 0 ; I <postedvalues. allkeys. length; I ++)
{
Nextkey = postedvalues. allkeys [I];
If (Nextkey. substring ( 0 , 2 )! = " __ " )
{
Displayvalues. append ( " <Br> " );
Displayvalues. append (nextkey );
Displayvalues. append (" = " );
Displayvalues. append (postedvalues [I]);
}
}
Receiveddatalabel. Text = displayvalues. tostring ();

}

4. Use public properties

(1) Source Page

 Note: This method is rarely used, but it is still used in some cases.

 Public StringDatatosend
{
Get
{
ReturnDatatosendtextbox. text;
}
}

Protected VoidPublicpropertiesbutton_click (ObjectSender, eventargs E)
{
Server. Transfer ("Publicpropertiespage. aspx");
}

(2) Target page

 

 <  Div  > 
< H1 > Target page-public properties </ H1 >
The data already ed from the source page is: <% = Previouspage. datatosend %> < BR /> < BR />
< ASP: hyperlink ID = "Hyperlink1" Runat = "Server" Navigateurl = "~ /Default. aspx" > Return to Source Page </ ASP: hyperlink >
</ Div >

5. Use Control Infomation

(1) Source Page

 Note: In the past, I used to go to findcontrol () only when I applied the master page.

<ASP: textboxID= "Datatosendtextbox"Runat= "Server"Text= "Hello world! "> </ASP: textbox> <BR/> <BR/>


 Protected VoidControlinfobutton_click (ObjectSender, eventargs E)
{
Server. Transfer ("Controlinfopage. aspx");
}

(2) Target page

 

 <  H1  > Target page-control info </  H1  > 
The data already ed from the source page is:
< ASP: Label ID = "Datareceivedlabel" Runat = "Server" Text = "Label" > </ ASP: Label > < BR /> < BR />

 

Protected VoidPage_load (ObjectSender, eventargs E)
{
VaRTextbox = previouspage. findcontrol ("Datatosendtextbox")AsTextbox;
If(Textbox! =Null)
{
Datareceivedlabel. Text = textbox. text;
}

}

Reflection: It seems that the author has not put cookies in this category, why?

 

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.