PC6下载站

分类分类

如何快速清除所有TextBox的值

关注+2010-01-28作者:

C#代码

public static void SetControlReadOnly(Control ctr)
        {
           
if (ctr is TextBox)
            {
                TextBox txtControl
= (TextBox)ctr;
                txtControl.ReadOnly
= true;
                txtControl.Enabled
= false;

            }
           
else if (ctr is RadioButton) { RadioButton btn = (RadioButton)ctr;
                btn.Enabled
= false;

            }
           
else if (ctr is Button)
            {
                Button btn
= (Button)ctr;
                btn.Enabled
= false;

            }
           
else if (ctr is FileUpload)
            {
                FileUpload btn
= (FileUpload)ctr;
                btn.Enabled
= false;

            }  
           
else if (ctr is RadioButtonList)
            {
                RadioButtonList btn
= (RadioButtonList)ctr;
                btn.Enabled
= false;
            }

           
else if (ctr is CheckBox)
            {
                CheckBox cb
= (CheckBox)ctr;
                cb.Enabled
= false;
            }
           
else if (ctr is CheckBoxList)
            {
                CheckBoxList cb
= (CheckBoxList)ctr;
                cb.Enabled
= false;
            }
           
else if (ctr is DropDownList)
            {
                DropDownList list
= (DropDownList)ctr;
                list.Enabled
= false;
            }

           
else if (ctr is HtmlTextArea)
            {
                HtmlTextArea cb
= (HtmlTextArea)ctr;
                cb.Attributes.Add(
"readonly", "");
                cb.Disabled
= true;
            }
           
else if (ctr is HtmlSelect)
            {
                HtmlSelect rb
= (HtmlSelect)ctr;
                rb.Disabled
= true;
            }

           
else if (ctr is HtmlInputCheckBox)
            {
                HtmlInputCheckBox rb
= (HtmlInputCheckBox)ctr;
                rb.Disabled
= true;
            }
           
else if (ctr is HtmlInputRadioButton)
            {
                HtmlInputRadioButton rb
= (HtmlInputRadioButton)ctr;
                rb.Disabled
= true;
            }
           
else if (ctr is HtmlInputText)
            {
                HtmlInputControl input
= (HtmlInputControl)ctr;
                input.Attributes.Add(
"readonly", "");
                input.Disabled
= true;
            }
            
else if (ctr is HtmlInputFile)
            {
                HtmlInputFile input
= (HtmlInputFile)ctr;
                input.Attributes.Add(
"readonly", "");
                input.Disabled
= true;
            }
               
           
else
               
foreach (Control ctr1 in ctr.Controls)
                {
                    SetControlReadOnly(ctr1);
                }
        }

JS代码

因为textbox和HtmlInputText在客户端生成出来就是textarea和input[type=text],只要用js清除这两种标签的值就可以了

document.getElementsByName('text')

 

展开全部

相关文章

更多+相同厂商

热门推荐

  • 最新排行
  • 最热排行
  • 评分最高
排行榜

    点击查看更多

      点击查看更多

        点击查看更多

        说两句网友评论

          我要评论...
          取消