How to set up custom control in cs homepage file

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

+3
source share
3 answers

If you add it to the ContentPlaceHolder and the child page adds content to this ContentPlaceHolder, the user control will no longer be displayed. IOW, the controls you add are only the default.

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

+3
source

I'm not sure, but I think you need to use Page.LoadControl () to officially load the user control onto the page at runtime.

0
source

If I read it correctly, do you have a control on the main page and need to link to it from child pages in order to change its visibility? Or is something wrong with me?

In any case, this is how I usually do it in VB.Net, it should not be too difficult to port; -)

On the aspx page:

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

In code:

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

All Articles