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