How to Instantiate User control in Master page cs file?

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 .

Up vote 2 down vote favorite 1 share g+ share fb share tw.

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 asp.net . Net-3.

5 master-pages usercontrols link|improve this question edited Aug 7 '09 at 19:57Brant Bobby2,19621343 asked Dec 2 '08 at 21:53alice7690926 56% accept rate.

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.

In other words... any tags placed inside a ContentPlaceHolder on a master page will function as default content, but generally they are replaced by the tags inside the corresponding Content tag of a content page, unless the content page omits such a corresponding Content tag. – Triynko Jul 28 '11 at 18:31.

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.

User controls loaded at runtime need to be loaded with LoadControl, rather than "new MyUserControl", because otherwise the control's tags aren't parsed and none of the control's child objects will be instantiated. That will result in surprises like unexpected null controls and problems restoring viewstate. But anyway, for this particular question, I think it's just what Mark Brackett said... the stuff inside the ContentPlaceHolder on the master page is getting replaced by the stuff in the corresponding Content tag of the child page (unless content page omits mentioned corresponding tag).

– Triynko Jul 28 '11 at 18:25.

Anyway, here's how I commonly do it in VB . Net, it shouldn't be too hard to port ;-) In the aspx page: In the code-behind: Dim customControl As ASP. Customcontrol_ascx = Master.

FindControl("customControl") If customControl IsNot Nothing Then ... End If.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions