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 ();
}