asp.net|web| Control
In ASP.net 2.0, to invoke each other between different Web controls, you must <%@ Reference virtualpath= "Another control name" > to refer to the following example
Default.aspx:
<form id= "Form1" runat= "Server" >
<uc1:webusercontrol id= "WebUserControl1" runat= "Server" >
</uc1:WebUserControl>
<uc2:webusercontrol2 id= "webusercontrol2_1" runat= "Server"/>
</form>
What we want to achieve is that when you press the button on control 1, the specified text is displayed in the text box in Control 2.
In the home page, control 1 and control 2 are called separately
Webcontrol.ascx:
<%@ control language= "C #" autoeventwireup= "true" codefile= "WebUserControl.ascx.cs" inherits= "Webusercontrol"% >
<%@ Reference virtualpath= "~/webusercontrol2.ascx"%>
<asp:button id= "Button1" runat= "Server" text= "button"/>
Place a button here, and then use reference to refer to the control 2
Webcontrol.ascx.cs:
protected void Button1_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 code for Control 2:
public partial class WebUserControl2:System.Web.UI.UserControl
{
protected void Page_Load (object sender, EventArgs e)
{
}
public string Text
{
set {TextBox1.Text = value;}
}
}