• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1178
  • Last Modified:

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
0
mugsey
Asked:
mugsey
  • 2
  • 2
1 Solution
 
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
 
sijishJohnCommented:
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

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now