I'm not sure what you're doing wrong so I created a simple project with 2 user controls in it and a WebForm.
Here is UserControlA.ascx:
(ASP Code)
-
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControlA.ascx.cs"
-
Inherits="WebApplication1.UserControlA" %>
-
<asp:Panel ID="PersonInfoContent" runat="server" Style="margin: 2em 0 0 0;">
-
<fieldset>
-
<legend>Person Information (User Control A)</legend>
-
<asp:Label ID="PersonInfo" runat="server" Style="float: right; display: block;" />
-
<label for="<%=Name.ClientID %>">First Name:</label>
-
<asp:TextBox ID="Name" runat="server" />
-
<br />
-
<label for="<%=LastName.ClientID %>">Last Name:</label>
-
<asp:TextBox ID="LastName" runat="server" />
-
<br />
-
<asp:Button ID="UpdatePersonInfo" runat="server" Text="Update Person" OnClick="UpdatePersonInfo_Click" />
-
</fieldset>
-
</asp:Panel>
-
(C# code behind)
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
-
namespace WebApplication1
-
{
-
public partial class UserControlA : System.Web.UI.UserControl
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{}
-
-
protected void UpdatePersonInfo_Click(object sender, EventArgs e)
-
{
-
DisplayPersonInfo();
-
}
-
public void DisplayPersonInfo()
-
{
-
PersonInfo.Text = String.Format("{0} {1} {2}","Updated name:", Name.Text, LastName.Text);
-
}
-
}
-
}
Here's UserControlB.ascx:
(ASP Code)
-
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControlB.ascx.cs" Inherits="WebApplication1.UserControlB" %>
-
<%@ Register Src="UserControlA.ascx" TagName="UserControlA" TagPrefix="uc1" %>
-
-
<fieldset style="margin: 0 auto; width: 50%">
-
<legend>Person And Phone Information (User Control B)</legend>
-
<uc1:UserControlA ID="UserControlAInstance" runat="server" />
-
<asp:Panel ID="PhoneNumberContent" runat="server" Style="margin: 2em 0 0 0;">
-
<asp:Label ID="PhoneDetails" runat="server" Style="display: block; float: right;" />
-
<label for="<%=PhoneNumber.ClientID %>">Phone Number:</label>
-
<asp:TextBox ID="PhoneNumber" runat="server" />
-
</asp:Panel>
-
<asp:Button ID="UpdateALL" runat="server" Text="Update Person And Phone Number" OnClick="UpdateALL_Click" />
-
</fieldset>
(C# code behind)
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
-
namespace WebApplication1
-
{
-
public partial class UserControlB : System.Web.UI.UserControl
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{}
-
-
protected void UpdateALL_Click(object sender, EventArgs e)
-
{
-
UserControlAInstance.DisplayPersonInfo();
-
PhoneDetails.Text = String.Format("{0} {1}","Updated Phone Number:", PhoneNumber.Text);
-
}
-
}
-
}
And here's my WebForm1.aspx (I have no code behind for it)
-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
-
<%@ Register src="UserControlB.ascx" tagname="UserControlB" tagprefix="uc1" %>
-
-
<!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></title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<uc1:UserControlB ID="UserControlB" runat="server" />
-
<asp:Button ID="btn" runat="server" Text="Button in Form" />
-
</div>
-
</form>
-
</body>
-
</html>
You'll notice that if I click the button in UserControlA, the name details label is updated with the first and last name provided.
If I click the button in UserControlB, the name details label in UserControlA is updated and the phone number details label in UserControlB are updated.
If I click the button in the WebForm, neither of the user control's are updated (to see this you'll have to make changes to them before hitting the button).
-Frinny