Reading Notes: Liang Jian. Net -- Context. handler and context. Items

Source: Internet
Author: User

(1) Context. Handler

Send pageWebforme1. Aspx html

 

< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: textbox ID = "Textbox1" Text = "Litianping" Runat = "Server" > </ ASP: textbox >
< ASP: button ID = "Button1" Runat = "Server" Text = "Go to webforme2.aspx"  
Onclick = "Button#click"   />
</ Div >
</ Form >

 

Send page:Webforme1. Aspx CSCode

Protected   Void Button#click ( Object Sender, eventargs E)
{
Server. Transfer ( " Webforme2.aspx " );
}

 

HTML of webforme2.aspx on the receiving page

 

< Form ID = "Form1" Runat = "Server" >
< Div >
Receiving value: < ASP: textbox ID ="Textbox1" Runat = "Server" > </ ASP: textbox >
</ Div >
</ Form >

 

CS code of webforme2.aspx on the receiving page

 

Protected   Void Page_load ( Object Sender, eventargs E)
{
// Get the page object from post
If (Context. Handler Is  Webforme1)
{
// Retrieve page objects
Webforme1Poster = (Webforme1) Context. Handler;

// Get control
This . Textbox1.text = (Textbox) Poster. findcontrol ( " Textbox1 " ). Text;
// This. textbox1.text = poster. textbox1.text;
}
}

 

 

(2) Context. handler get public variables

Send page:Webformf1. Aspx CS code

// Define a public variable
Public   String  Strname  =   " Litianping " ;
Protected   Void Page_load ( Object Sender, eventargs e ){}

Protected VoidButton#click (ObjectSender, eventargs E)
{
Server. Transfer ("Webformf2.aspx");
}

 

Receiving page:

 

Protected   Void Page_load ( Object Sender, eventargs E)
{
// Get the page object from post
If (Context. Handler Is  Webformf1)
{
// Retrieve page objects
Webformf1Poster = (Webformf1) Context. Handler;
This . Textbox1.text = Poster.Strname;
}
}

 


(3) Context. Items variable

Send page:Webformg1. Aspx html

 

< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: textbox ID = "Textbox1" Text = "Litianping" Runat = "Server" > </ ASP: textbox >
< ASP: button ID = "Button1" Runat = "Server" Text = "Enter webformg2.aspx"  
Onclick = "Button#click"   />
</ Div >
</ Form >

 

Sending page: CS code of webformg1.aspx

 

Protected   Void Button#click ( Object Sender, eventargs E)
{
Context. items [ " Name " ] = Textbox1.text;
Server. Transfer ( " Webformg2.aspx " );
}

 

Receiving page: CS code of webformg2.aspx

 

Protected   Void Page_load ( Object Sender, eventargs E)
{
// Get the page object from post
If (Context. Handler Is Webformg1)
{
This . Textbox1.text = Context. items [ " Name " ]. Tostring ();
}
}

 

The context object provides access to the entire current context (including the request object. You can use this object to share information between pages.

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.