WebForm aspx page value passing --- 7 methods, webform --- 7

Source: Internet
Author: User

WebForm aspx page value passing --- 7 methods, webform --- 7

1. get Method

Send page

<Form id = "form1" runat = "server">
<Div>
<A href = "WebForm2.aspx? Name = 5 "> transfer to Form2 </a>
<Asp: Button ID = "button2" Text = "Jump page" runat = "server" onclick = "button2_Click"/>
</Div>
</Form>

Protected void button2_Click (object sender, EventArgs e)
{
Response. Redirect ("WebForm2.aspx? Name = 5 ");

}

Acceptance page

This. Label1.Text = Request ["name"];
// This. Label2.Text = Request. Params ["name"];
// This. Label3.Text = Request. QueryString [0];

 

2. post Method

A \ without runat = "server"

Send page

<Form id = "form2" action = "WebForm2.aspx" method = "post">
<Input name = "txtname" type = "text" value = "lilili"/>
<Input type = "submit" value = "submit webpage"/>
</Form>

Acceptance page

This. Label1.Text = Request. Form ["txtname"];

B \ with runat = "server"

Send page

<Form runat = "server" id = "form3">
<Input id = "btnTransfer" type = "button" onclick = "post ();" runat = "server" value = ""/>
</Form>
<Form id = "form4" method = "post">
<Input type = "text" runat = "server" id = "txtname" value = "lili"/>
</Form>
<Script type = "text/javascript">
Function post (){
Form4.action = "WebForm2.aspx ";
Form4.submit ();
}
</Script>

Acceptance page

This. Label1.Text = Request. Form ["txtname"];

 

3. Session and Application

Session ["name2"] = "sessontest ";
Application ["name3"] = "applicationtest ";

 

This. Label2.Text = (string) Session ["name2"];
This. Label3.Text = (string) Application ["name3"];

 

4. Static variables

Send page

 

Public static string statest = "static string ";

Protected void button2_Click (object sender, EventArgs e)
{
Server. Transfer ("WebForm2.aspx ");
}

Acceptance page

This. Label1.Text = WebForm1.statest;

 

5. Get the control using Context. Handler.

Send page

<Asp: TextBox ID = "TextBox1" runat = "server" Text = "lilili"> </asp: TextBox>
<Asp: Button ID = "button2" Text = "Jump page" runat = "server" onclick = "button2_Click"/>

Protected void button2_Click (object sender, EventArgs e)
{
Server. Transfer ("WebForm2.aspx ");
}

  

Acceptance page

// Obtain the object passed by post
If (Context. Handler is WebForm1)
{
WebForm1 poster = (WebForm1) Context. Handler;
This. Label1.Text = (TextBox) poster. FindControl ("TextBox1"). Text;
}

 

6. Context. Handler gets public variables

Send page

Public string testpost = "testpost ";
Protected void button2_Click (object sender, EventArgs e)
{
Server. Transfer ("WebForm2.aspx ");
}

Acceptance page

// Obtain the object passed by post
If (Context. Handler is WebForm1)
{
WebForm1 poster = (WebForm1) Context. Handler;
This. Label2.Text = poster. testpost;
}

 

7. Context. Items variable

Send page

Protected void button2_Click (object sender, EventArgs e)
{
Context. Items ["name"] = "contextItems ";
Server. Transfer ("WebForm2.aspx ");
}

Acceptance page

// Obtain the object passed by post
If (Context. Handler is WebForm1)
{
This. Label3.Text = Context. Items ["name"]. ToString ();
}

Related Article

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.