Solved

programmatically access user control on master page

Posted on 2008-10-09
5
1,166 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now