showproduct.aspx页面里分别加裁两个控件c1.ascx,c2.ascx,c2.aspx有控件<asp:Label ID="laDepict" runat="Server"></asp:Label>,现在我要在c1里查找c2里的控件Label laDepict = (Label)Page.FindControl("laDepict");提示出错,找不到

解决方案 »

  1.   

    先找到 用户控件再用findcontrol
      

  2.   

    c2.ascx 本身有个ID,
    其子元素的ClientID = 父ID_子ID (父ID$子ID)如果能访问C2.laDepict的话,还有直接可以 C2.laDepict.ClientID
      

  3.   

    新建的web技术交流群,欢迎大家加入一起讨论:
    群号:29037453
      

  4.   

    用户控件中ID 再根据用户控件的ID 查找 具体的控件名称 
      

  5.   

    为你的c2.ascx开放一个接口属性:public Label laDepict
    {
        get
        {
            this.EnsureChildControls();
            return this.laDepict;
        }
    }
    这样别的组件就可以访问它公开的接口功能了,而不用管它内部是如何是如何实现的。
      

  6.   

    UserControl c = (UserControl)FindControl("YourUserControlID"); 
    if (c!= null) 
      {
    Label l=c.FindControl("") AS Label; 

      

  7.   

    c1里查找c2里的控件Label
    c1.findcontrol(c2).find(label)
      

  8.   

    c2.ascx 里的控件 好像是protected的  就是说 在其他不是其子类的页面访问不到的!
    在你的代码里 加个属性
      

  9.   

    我不建议用继承,想必你既然做了2个用户控件他们之间的功能是不有独立区分的。
    你这样做:
    1.在c2.ascx中添加一个属性,如:
    public Label MyLabel
    {
       get { return this.laDepict; }
    }
    2.在c1.ascx中添加一个属性,如:
    private _lableInc2=null;
    public Label LableInc2
    {
       set{ _lableInc2=value; }
    }
    3.在showproduct.aspx页面中写
    this.c1.LableInc2=this.c2.MyLabel;
    4.然后你就能在c1中通过属性LableInc2使用到c2里的laDepict了
      

  10.   


    引用“用户控件的类名”不知道何意。在你为用户控件新增属性之后,应该先编译(Shit+F6),这样就可以在包含这个用户控件的页面上直接访问这个用户控件的新增属性了。