views:

461

answers:

3

I have included a user control in another statically following code :


place the folowing directive in the asp code of the parent page or usercontrol:

<%@ Register src="Name_of_your_child_control.ascx" tagname="Name_of_your_child_control" tagprefix="uc1" %>

use the following tag in the asp-code of the parent page/control:

<uc1:Name_of_your_child_control ID="Name_of_your_child_control1" runat="server" />

..... But the issue is...i am not able to access the public properties of user control which got included(child user control) in given user control(parent user control)...

Please help :(

A: 

Using

Name_of_your_child_control1.PublicPropertyName

must work for your parent user control.

sashaeve
+1  A: 

Say your usercontrol was this:

<%@ Control Inherits="Project.MyControl" Codebehind="MyControl.ascx.cs" %>
<asp:TextBox ID="TB" runat="server" />

Your control code-behind:

namespace Project 
{
  public partial class MyControl : UserControl
  {
    public string MyTextProperty
    {
      get { return TB.Text; }
      set { TB.Text = value; }
    }
  }
}

In your parent page that included the control, like this:

<%@ Register src="~/MyControl.ascx" tagname="MyControl" tagprefix="uc1" %>
<uc1:MyControl ID="MyControlID" runat="server" />

You can use that property in code:

MyControlID.MyTextProperty = "bob";
Nick Craver
But ...for me it is coming as i can not access the property :(
Anish Mohan
@Anish - If you reference it as if it were there and compile, what error do you get?
Nick Craver
Is ur parent page is also a user control ?Parent Page{uc1{uc2{}}}
Anish Mohan
@Anish - You want to access the property from the Parent control's code-behind, or from the page's codebehind that contains the parent?
Nick Craver
I have 2 user controls : uc1 and uc2Also a parent page p1.I have included uc1 inside p1.Now i need to include uc2 inside uc1...and access uc2 property inside uc1
Anish Mohan
@Anish - If you follow my answer, just including the control in a UserControl instead of a page it should work just the same, you should be able to use `MyControlID.MyTextProperty` in the code-behind of the parent user control, what compile error do you get if you try?
Nick Craver
A: 

Check the path and file names you are using, Anish. You have something wrong. Is Visual Studio telling you it can't find the control? Is it failing at compile time? Runtime?

Bryan