Loading ...

Problem with usercontrol...

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » Problem with usercontrol...

Problem with usercontrol...

Posts under the topic: Problem with usercontrol...

Posted: 3/3/2009

Lurker 10  points  Lurker
  • Joined on: 12/22/2008
  • Posts: 4

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

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79

Are you using masterpages? If yes, then note that masterpage itself comes first in hierarchy as a child control of the page.


Posted: 3/5/2009

Lurker 10  points  Lurker
  • Joined on: 12/22/2008
  • Posts: 4

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.


Posted: 3/5/2009

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79
  Answered

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

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

dpkngm said:

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


Page 1 of 1 (5 items)