How to access page controls from user control?

后端 未结 4 1988
长情又很酷
长情又很酷 2020-12-18 10:08

Is there a way to access page controls from user control . I have some controls in my page and i want to access these controls from the user control .

4条回答
  •  不知归路
    2020-12-18 10:23

    its work for me :

    I declare Label in My .aspx page

      
      
    

    In .aspx.cs I have add UserControl through Panel

       UserControl objControl = (UserControl)Page.LoadControl("~/ts1.ascx");
       pnlUC.Controls.Add(objControl);
    

    and access from in .ascx UserControl like this :

     Page page = this.Page;
     Label lbl = page.FindControl("lblpage") as Label;
     string textval = lbl.Text;
    

提交回复
热议问题