Click here to Skip to main content
15,616,520 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i want to access masterpage controls from another page but its not child to master.
any idea please.

i use the code below but i get error

HtmlGenericControl div1 = new HtmlGenericControl("Div");
MasterPage master = new MasterPage();
master.MasterPageFile = "PAHW.DefaultMaster";
div1 = (HtmlGenericControl)master.FindControl("DivOrgChart");
div1.Visible = false;

Thank you.

use like this
MasterPage mstpage = new MasterPage();
TextBox txt = (TextBox)mstpage.FindControl("controlid");
Share this answer
You can access, but need to add master page registry directive.

like below:


Then u can access the master page, i think.
Share this answer
if your page is not using master page, controls on master page will not render. It mean you can't access it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900