views:

1463

answers:

3

I have added uc in contentplace holder of master page but how do you instantiate the user control in master page .cs file to make it visible when the master page loads

+1  A: 

If you add it to a ContentPlaceHolder, and a child page adds content to that ContentPlaceHolder - you're user control will no longer appear. IOW, the controls you add are only the default.

Just add it outside of the ContentPlaceHolder if you want it always visible.

Mark Brackett
A: 

I'm not positive but I think you need to use the Page.LoadControl() to officially load a user control to a page at run time.

Chris
A: 

If I read this correctly, you have a control in a Master page and need to reference it from the child pages to change it's visibility? Or have I got things around the wrong way?

Anyway, here's how I commonly do it in VB .Net, it shouldn't be too hard to port ;-)

In the aspx page:

<%@ Reference Control="~/path/to/my/customControl.ascx" %>

In the code-behind:

Dim customControl As ASP.customcontrol_ascx = Master.FindControl("customControl")
If customControl IsNot Nothing Then
    ...
End If
Pat