Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

programmatically access user control on master page

Posted on 2008-10-09
5
Medium Priority
?
1,177 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Screencast - Getting to Know the Pipeline

916 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