当前位置:编程学习 > C#/ASP.NET >>

一个小问题 控件的

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control co in Page.Controls)
        {
            if (co is TextBox)
            {
                
                TextBox b = (System.Web.UI.WebControls.TextBox)co;


                b.Text = string.Empty;
           
            }
        }
    }


我想对页面所有TextBox控件进行操作;可惜实现不了string.Empty;是我哪写错的么 --------------------编程问答-------------------- Page.Controls    -》  form1。Controls     --------------------编程问答--------------------  b.Text = "";
就可以了,
浏览器没有null值这个东西 --------------------编程问答-------------------- textBox在页面源码里都是input,用js的方法就行了


function Setvalue()
{
   var a=document.getElementsByTagName("input");
   for(var i=0;i<a.length;i++)
   {
     if(a[i].type="Text")
     {
      a[i].value="";
     }
}
}
--------------------编程问答-------------------- if(a[i].type="Text")
这个是if(a[i].type=="Text")
--------------------编程问答--------------------
   protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox txt = null;
            foreach (Control co in Page.Controls)
            {
                if (co.GetType().Name == "HtmlForm")
                {
                    foreach (Control c1 in co.Controls)
                    {
                        if (c1.GetType().Name == "TextBox")
                        {
                            txt = ((TextBox)c1);
                            txt.Text = "bbb";
                        }
                    }
                }
            }
        }
--------------------编程问答--------------------
引用 5 楼 wxr0323 的回复:
C# code
   protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox txt = null;
            foreach (Control co in Page.Controls)
            {
                if (……


正解。。 --------------------编程问答--------------------
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,