Avatar of centdevs
centdevs asked on

How do I set a usercontrol property from a child page

I have a user control in a master page, and I need to set one of it's custom properties from a child page.  How can I do this?

Avatar of undefined
Last Comment

8/22/2022 - Mon

You can achieve this through the master property of the child page and the FindControl() method.

To demonstrate how, add a button named Button1 to the master page and write the following code in the child page:
    Button b = (Button) Master.FindControl("Button1");
    b.Text = "Hi";

Open in new window

Anurag Thakur

i have coppied the following text from the link below

You can use two methods. The first is by using Page.Master.FindControl('controlID'). Then you can cast it to the type of your user control. The second method is by adding a <%@ MasterType VirtualPath="" TypeName=""%> tag to your aspx page. In the VirtualPath add the virtual path to the master page, and the class in the TypeName. You can then access everything with intellisense.


How do I find the type to cast to?  Like, instead of (Button) ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question