Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a user control property on a user control in a asp.net page

Status
Not open for further replies.

Tokhra

Programmer
Oct 1, 2003
134
ES
Hi All,

I have a user control named "Header.ascx", which is the header for my website, within this control there is a leftPanel Panel. In the codebehind for this control I have added the line

System.Web.UI.UserControl SubMenu;

then in the page load I have:

if (SubMenu != null)
{
leftPanel.Controls.Add(SubMenu);
}

So the idea is that, in default.aspx I can include the header control:

<%@ Page language=&quot;c#&quot; Codebehind=&quot;Default.aspx.cs&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;Bleh.Default&quot; %>
<%@ Register TagPrefix=&quot;Bleh&quot; TagName=&quot;Header&quot; Src=&quot;Controls/Header.ascx&quot; %>


<Bleh:Header runat=&quot;server&quot;></Bleh:Header>

And it adds the Header usercontrol to the default.aspx page..but now I face the problem of setting Header.aspx's SubMenu property..

The point of this is that different pages have different submenus, so I need to be able to change it.

Any ideas how I can set the Header controls SubMenu property when adding it to Default.aspx?

Thanks,
Matt.
 
Got it, in the page_load on default.aspx I have

Header myControl = (Header) this.Controls[0];
myControl.SubMenu = new Bleh.SubMenus.MySubMenu();

Then the page_load on the Header takes care of adding it to the leftPanel Panel.

That adds the control, but it doesn't display it..

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top