如何在后台代码中找前台控件,不用JS

解决方案 »

  1.   

    如果是服务端控件,可以用FindControl方法找到。
      

  2.   

    后可当然不用js,如果知道ID,可以用它的直接父控件的FindControl(id)来做不知道ID,可以遍历他父控件的子控件,通过某一特殊属性检查后来做。
      

  3.   

    肯定有父控件的,起码是formButton  btn = this.Form1.FindControl("Button1");
      

  4.   

    foreach(Control ctrl in this.controls) 
    { if(ctrl is Label){}
    }
    TextBox tb= Page.FindControl("") as TextBox;
      

  5.   


    Button  btn = this.Form1.FindControl("Button1");  服务器控件Request.Params["控件ID"] HTML控件值
      

  6.   


    //手写的,字母大小写问题自己解决
    foreach(System.Web.UI.Control control in this.controls)
    {
       if(control is Label)  //若是label
       {
            Label lb = (Label)control;
        }
    }