Mutual invocation between different Web controls in asp.net 2.0

Source: Internet
Author: User
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;}

}

}



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.