页面构造是这样的:
最外面是母版页,叫ContentPlaceHolder1
第二层是:repeater
叫:repeater1
最里面是一个:button共有十个页面,其中一个页面是这样的构造。我需要在每个页面加载时去判断当前这个页面是否有这个按钮,如果有,则设为不可用。
如何做?我的想法是写个页面基类,在页面加载时,去找该控件,但我现在发现用ControlCollection的FindControl用name能找到该控件,但用它的ID就找不到。这个name与ID我都是在生成的html里找到,再测试的。

解决方案 »

  1.   

    在客户端ID是这样的:ContentPlaceHolder1_Rep_Center_btndel_1  ,ContentPlaceHolder1_Rep_Center_btndel_2.。。name是这样的:ctl00$ContentPlaceHolder1$Rep_Center$ctl00$btndel  ctl00$ContentPlaceHolder1$Rep_Center$ctl01$btndel
      

  2.   

    Repeater在母版页还是内容页中?
      

  3.   

    foreach(RepeaterList item  in  repeater1.Items)
    {   Button   bu=(Button)item.controls[0].FindControl('buttonId');
    }  
      

  4.   


    //喔 知道了 在内容页
            if (!IsPostBack)
            {
                Repeater1.DataSource = getTable();
                Repeater1.DataBind();
                foreach (RepeaterItem item in Repeater1.Items)
                {
                    Button btn = item.FindControl("Button1") as Button;
                    if (btn != null)
                        btn.Enabled = false;
                }
            }
      

  5.   


    public class Class1 : System.Web.UI.Page
    {
        public void Enabled(Repeater rep)
        {
            foreach (RepeaterItem item in rep.Items)
            {
                Button btn = item.FindControl("Button1") as Button;
                if (btn != null)
                    btn.Enabled = false;
            }
        }
    }
    public partial class _Default : Class1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater1.DataSource = getTable();
                Repeater1.DataBind();
                Enabled(Repeater1);
            }
        }
    }
      

  6.   

    YourContro.ClinetID   表示改控件在展现为html后的   id如果你要自己用js
    可以用ClientID来得到
    比如:<script>
    function   check(){
    var   box   =   ' <%=   YourTextBox.ClientID%> ';
    if(document.getElementById(box).value.lehgth   <5){
    window.alert( '不能少于5位阿 ');
    }
    }
    </script> 
      

  7.   

    楼上,我用c#写,不使用js
    我现在就是c#写的,是一层一层的找,但就是用它的ID找不到,但用NAME却能找到?为什么?好奇怪
      

  8.   

    加了runnat属性可以FIND到。不加则在表单里找