Mutual calls between different Web controls in Asp.net 2.0

Source: Internet
Author: User

In Asp.net 2.0, to call each other between different Web controls, you must <% @ reference virtualpath = "another control name">
For example:

Default. aspx:
<Form ID = "form1" runat = "server">
<Uc1: webusercontrol id = "webusercontrol1" runat = "server">
</Uc1: webusercontrol>
<UC2: webusercontrol2 id = "webusercontrol2_1" runat = "server"/>
</Form>

To achieve this, after pressing the button of Control 1, the specified text will be displayed in the text box of Control 2.

On the homepage, control 1 and Control 2 are called respectively.

Webcontrol. ascx:

<% @ Control Language = "C #" autoeventwireup = "true" codefile = "webusercontrol. ascx. cs" inherits = "webusercontrol" %>

<% @ Reference virtualpath = "~ /Webusercontrol2.ascx "%>

<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>

Place a button here and use reference to reference Control 2
Webcontrol. ascx. CS:
Protected void button#click (Object sender, eventargs E)
{

Webusercontrol2 W = page. findcontrol ("webusercontrol2_1") as webusercontrol2;
W. Text = "Hello all! ";

}

For control 2:
<% @ Control Language = "C #" autoeventwireup = "true" codefile = "webusercontrol2.ascx. cs" inherits = "webusercontrol2" %>

<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
Codebehind of Control 2Code:
Public partial class webusercontrol2: system. Web. UI. usercontrol
{
Protected void page_load (Object sender, eventargs E)
{

}
Public String text
{

Set {textbox1.text = value ;}

}

}

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.