Last post Mar 16, 2007 09:36 AM by jbeall
Feb 21, 2007 02:01 AM|allenrajiev|LINK
I have the names of Some server controls in string variables. It can be textbox or linkbutton or button or anything.
I want to hide these controls depending on some conditions.
How can i get access to these controls. I am using master page. But these controls are in content page.
I tried, this.page.Findcontrol(ctrName) , but its returning null, though its very much there in the page. I can access this controls using this.btnSave and all, but I cant use this.ctrName, being ctrName a string.
Also is there any way to cast anytype of Control to a common contol?
What if i am having some controls in User controls, what If I am having some custom controls. how will i access, controls inside that in present page.
Thanks for tyhe help
Feb 21, 2007 02:56 AM|Haissam|LINK
The common control to cast is the Control object
Control ctr = (Control)Page.FindControl("CONTROLID")
try to look into the below link
MasterPage And Page.FindControl
Feb 21, 2007 03:03 AM|allenrajiev|LINK
Feb 21, 2007 03:09 AM|XOR_|LINK
Feb 21, 2007 03:13 AM|allenrajiev|LINK
will this much code be enough? Please let me know if u need full code of aspx n cs
Feb 21, 2007 03:23 AM|XOR_|LINK
because ur control exist in a content place holder try
Feb 21, 2007 04:16 AM|allenrajiev|LINK
Feb 21, 2007 05:03 AM|allenrajiev|LINK
To get a control in the <childMaster> page, it’s a bit tricky but
keep in mind two thingsAll controls are in the topmost master page.
Controls that belong to child master pages are in the appropriate
ContentPlaceHolder control in the topmost master page. Now take a look at the trace output and check this code snippet below
Button btn =
btn.Text = "by the content page";
This will help and it worked for me..Thank you all..
Mar 16, 2007 09:36 AM|jbeall|LINK
I decided to go with recursive lookups. Rick Strahl has a code snippet demonstrating how to do this. I simply overrode the FindControl method to use recursive lookups if it couldn't find the control on the first pass.