是否没有通过(应用母版页)识别WebForm中的控件? [英] Did not identify Controls in the WebForm with (Master page applied)?

查看:57
本文介绍了是否没有通过(应用母版页)识别WebForm中的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想通过调用以下方法来启用所有文本框和DropDownLists.但这对我不起作用.很简单,它无法识别Contents Space Holder下的控件.有人可以针对这种情况建议一种方法吗?在此先谢谢!!




simply i want to enable all the text boxes and DropDownLists by calling following method.but it does not worked for me. simple it did not recognised the controls under Contents Space Holder.Can any one Could Suggest a method for this Situation? Thanks in advance!!!




protected void BtnAdd_Click(object sender, EventArgs e)
       {

           foreach (Control c in Controls)
           {
               if (c is TextBox)
               {
                   if (((TextBox)(c)).Enabled == false)
                   {
                       ((TextBox)(c)).Enabled = true;

                   }


               }
               else if (c is DropDownList)
               {
                   if (((DropDownList)(c)).Enabled == false)
                   {

                       ((DropDownList)(c)).Enabled = true;
                   }

               }



           }
       }

推荐答案



检查这些

http://codeasp. net/blogs/raghav_khunger/microsoft-net/770/asp-net-how-to-find-all-textboxes-in-a-page [ http://forums.asp.net/t/1294337.aspx [ http://www.dreamincode.net/forums /topic/37343-how-to-clear-all-textboxes-on-one-page/ [ http://www.tek-tips.com/faqs.cfm?fid=6470 [ ^ ]

希望对您有帮助
Hi,

check these

http://codeasp.net/blogs/raghav_khunger/microsoft-net/770/asp-net-how-to-find-all-textboxes-in-a-page[^]
http://forums.asp.net/t/1294337.aspx[^]
http://www.dreamincode.net/forums/topic/37343-how-to-clear-all-textboxes-on-one-page/[^]
http://www.tek-tips.com/faqs.cfm?fid=6470[^]

hope it helps


您好,
如果您直接将控件放在页面中,请尝试以下操作:
Hi,
If you are having the controls in the page directly, then try this:
foreach (Control c in Page.Controls) {
            if (c is TextBox) {
                TextBox txt = (TextBox)c;
                txt.Enabled = true;
            }
            if (c is DropDownList) {
                DropDownList dl = (DropDownList)c;
                dl.Enabled = true;
            }
        }


否则,您将不得不使用FindControl函数找到它:
像一样,如果您的文本框位于面板内部,则:


Otherwise you''ll have to find it using FindControl function:
Like , if your textbox is inside panel then:

TextBox txt = (TextBox)panel1.FindControl("Textbox1");



还有一件事,您还可以找到文本框的根控件,并遍历Root控件中的所有控件.
像:-



One more thing, you can also find the root control for the textboxes and iterate through all the controls in the Root control.
Like:--

Panel pnl=(Panel)Page.FindControl("pnl1");// suppose this panel is root control for all your control
//Now you can iterate through it and find the controls
foreach (Control c in pnl.Controls) {
     if (c is TextBox) {
         TextBox txt = (TextBox)c;
         txt.Enabled = true;
     }
     if (c is DropDownList) {
         DropDownList dl = (DropDownList)c;
         dl.Enabled = true;
     }
 }



--Amit



--Amit


这篇关于是否没有通过(应用母版页)识别WebForm中的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆