programmatically access user control on master page

I have a dropdown user control that is on a master page in asp.net app.

How could I programmatically set the selected index of the dropdown control depending on what page is loaded in the asp.net application?   All the pages will dervie from the one master page
mugseyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sijishJohnConnect With a Mentor Commented:
I think you place the user control in another ContentPlaceHolder inside the second Master page...
try this code(attached)

If u still get error, pls  provide the HTML code of your second master page..


this.Master.Master.FindControl("<Name of ContentPlaceHolder>").FindControl("<Second ContentPlaceHolder>").FindControl("<User Control>");

Open in new window

0
 
Gyanendra SinghArchitectCommented:
in order to get a reference to your usercontrol from the Page, you need to do a Master.FindControl with the id of the user control. like this

Dim uc As UserControl = Master.FindControl("controlid")
0
 
mugseyAuthor Commented:
Yes thank you friend

The problem is I have top level materpage then a second master page that is inherited from the first.  This second masterpage is where the user control is.

For some reaon I cannot get a reference to it, it is always null

0
 
sijishJohnCommented:
try this


this.Master.Master.FindControl("<Name of ContentPlaceHolder>").FindControl("<User Control>")

Open in new window

0
 
mugseyAuthor Commented:
No it still does not work - hmm strange.  Will have a think
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.