ASP. net2.0 _ strong and weak methods for sending execution pages

Source: Internet
Author: User

Strongly typed method.

1. First in the Source PageCodeBlock, declare a public attribute;

2. Add the <% previouspagetype %> command in the rendering block of the target page, and specify the virtualpath attribute.

3. Use previouspage to directly call the Public attributes of the Source Page code block.

Example:

Source Page

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "typed. aspx. cs" inherits = "typed" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> strongly typed method </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "label1" runat = "server" associatedcontrolid = "textbox1" text = "name:"> </ASP: Label>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" onclick = "button#click" postbackurl = "~ /Testtyped. aspx"
TEXT = "complete"/> </div>
</Form>
</Body>
</Html>

 

 

Public partial class typed: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

Public String Username
{
Get
{
Return this. textbox1.text. tostring ();
}
}

Protected void button#click (Object sender, eventargs E)
{

}
}

 

Host page

Protected void page_load (Object sender, eventargs E)
{
If (previouspage! = NULL)
{
Response. Write (string. Format ("Welcome {0}. Use the strong method to send data across pages! ", Previouspage. username ));
}
}

 

Weak type method:

1. In the code block of the target page, use the findcontrol method of previouspage to obtain the corresponding control and then convert it;

2. Call the converted control property.

Example:

Source Page

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "untyped. aspx. cs" inherits = "_ default" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> weak type method </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "label1" runat = "server" text = "name:" associatedcontrolid = "textbox1"> </ASP: Label>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" text = "complete" postbackurl = "~ /Testuntyped. aspx "onclick =" button1_click "/> </div>
</Form>
</Body>
</Html>

 

 

Protected void page_load (Object sender, eventargs E)
{
If (previouspage! = NULL)
{
Textbox txtname = (textbox) previouspage. findcontrol ("textbox1 ");
Response. Write (string. Format ("Welcome {0} use the weak type method for sending data across pages! ", Txtname. Text. tostring ()));
}
}

 

 

 

Host page

protected void page_load (Object sender, eventargs e)
{< br> If (previouspage! = NULL)
{< br> response. Write (string. Format ("Welcome {0} to use the Forced method to send data across pages! ", Previouspage. username);
}< BR >}

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.