asp.net中重置按钮的实现


一 . 程序实现的方法
 
   //重置按钮事件
    protected void btn_Reset_Click(object sender, EventArgs e)
    {
        this.FindButton(this);
    }
    private void FindButton(Control c)
    {
        if (c.Controls != null)
        {

            foreach (Control x in c.Controls)
            {
                if (x is System.Web.UI.WebControls.TextBox)
                {
                    ((System.Web.UI.WebControls.TextBox)x).Text = "";
                }
                FindButton(x);
            }
        }
    }

二. javascript 实现方法

function ClearTextBoxValue()

{

        for(i=0;i<window.document.forms[0].elements.length;i++)

        {

                if(window.document.forms[0].elements[i].type=="text")         

                {

                       window.document.forms[0].elements[i].value="";

                }

        }

        return false;

}
后台调用代码如下:

this.btnReset.Attributes.Add("onclick","return ClearTextBoxValue()");


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM