Posted: 3/3/2009
dear friends in my application m having a label control on the parent page and not i want to access this from the usercontrol. i want to change the text property of the label. I have used this code but it is returning null.
Label lbl = (Label)this.Parent.Page.FindControl("lblErr");
if (lbl != null)
{
lbl.Text = "This shortname is already in use, please use a different shortname."; lbl.Visible = true;
Posted: 3/5/2009
Are you using masterpages? If yes, then note that masterpage itself comes first in hierarchy as a child control of the page.
Yes sir i am using master page, what do i need to do for accessing the label control.
Is there no way to find that label.
this blog entry might help you:
http://www.codeasp.net/blogs/vivek_iit/microsoft.net/135/how-to-access-child-controls-using-master-pages-in-asp.net
Posted: 4/15/2009
dpkngm said: i am using master page, what do i need to do for accessing the label control.
i am using master page, what do i need to do for accessing the label control.
Try something like this:
ContentPlaceHolder content = (ContentPlaceHolder)Page.Master.FindControl("Content1"); Label lbl = (Label)content.FindControl("UserControlID").FindControl("Label1"); if (lbl != null) { //do something }
I would also suggest you to read on this:
Master Pages and FindControl