Solved

programmatically access user control on master page

Posted on 2008-10-09
5
1,167 Views
Last Modified: 2012-05-05
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
Comment
Question by:mugsey
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22676804
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
 

Author Comment

by:mugsey
ID: 22676842
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
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22677482
try this


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

Open in new window

0
 

Author Comment

by:mugsey
ID: 22681207
No it still does not work - hmm strange.  Will have a think
0
 
LVL 4

Accepted Solution

by:
sijishJohn earned 500 total points
ID: 22684305
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now