怎样在继承母板页的页面里面寻找控件

举个例子:母板页面a.master 继承母板页的页面b.aspx
现在b.aspx里面有个textBOx控件,现在要在b.aspx里面写程序寻找textBOx控件

 

解决办法:

Control shousuoKJ = (Control)Master.FindControl("ContentPlaceHolder1");

textBOxCheckBoxs = (textBOx)shousuoKJ.FindControl("textBOxID" );

 

先找到母版页的控件ContentPlaceHolder1 然后再找textBOx。

 

再例如:遍历取checkBox的值和TEXT

 

<asp:CheckBox ID="CheckBox1" runat="server" Text="念佛菩萨圣号" ToolTip="善护口业" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="不妄言不恶口" ToolTip="善护口业" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="不两舌不绮语" ToolTip="善护口业" />
<asp:CheckBox ID="CheckBox4" runat="server" Text="行住坐卧散念" ToolTip="善护口业" />

-----------------------------------------------------------------------------------------------------------------------

string[] NeiRongs = new string[4];
       
        Control shousuoKJ = (Control)Master.FindControl("ContentPlaceHolder1");

                for (int cb = 1; cb <= 4; cb++)
                {
                    CheckBox CheckBoxs = (CheckBox)shousuoKJ.FindControl("CheckBox" + cb.ToString());
                    if (CheckBoxs != null)
                    {
                        if (CheckBoxs.Checked == true) { NeiRongs[cb - 1] = CheckBoxs.Text; }
                    }
                }
......

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xianfajushi/archive/2009/06/09/4255637.aspx

你可能感兴趣的:(server,String,null,asp,textbox)