如何在提交表单后重置所有控件 [英] how to reset all controls after submitting the form

查看:84
本文介绍了如何在提交表单后重置所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在提交表单后将所有控件设置为空

解决方案

参考:

简单易用的方法清除表单中的所有输入字段。 [< a href =http://www.codeproject.com/Tips/61790/Simple-and-easy-way-to-clear-all-the-input-fieldstarget =_ blanktitle =New Window> ^ ]

清除表单中所有输入字段的简单方法。 [ ^ ]


创建一个方法,在每个字符串中分配空字符串你想要清空的控制并在提交按钮后点击


你好,

方法1-

步骤1:

创建t他跟随aspx.cs中的函数

  private   void  ClearControls(ControlCollection ctrls)
{
foreach (在中控制ctrl ctrls)
{
if (ctrl TextBox)
( (TextBox)ctrl).Text = string .Empty;
else if (ctrl DropDownList)
((DropDownList)ctrl).ClearSelection();

ClearControls(ctrl.Controls);
}
}





步骤2:在提交按钮点击事件中调用ClearControls函数这个

 ClearControls(Page.Controls); 





Approach2-



在按钮点击事件中使用此代码:

 Form.Controls.Clear(); 





方法3-

在按钮点击事件中使用此代码:

 Page.Response.Redirect(Page.Request.Url.RawUrl)





Approach4-

使用此代码重定向到同一页面

 Response.Redirect(Request.Url.PathAndQuery, true ); 


i want to set all controls empty after submitting form

解决方案

Refer:
Simple and easy way to clear all the input fields in the form.[^]
Simple and easy way to clear all the input fields in the form.[^]


Create an method for Assign empty string in each control that you want to empty and call that method after submit button click


Hello,
Approach 1-
Step1:
Create the following function in aspx.cs

private void ClearControls(ControlCollection ctrls)
       {
           foreach (Control ctrl in ctrls)
           {
               if (ctrl is TextBox)
                   ((TextBox)ctrl).Text = string.Empty;
               else if (ctrl is DropDownList)
                   ((DropDownList)ctrl).ClearSelection();

               ClearControls(ctrl.Controls);
           }
       }



Step2: Call the ClearControls function in the Submit button click event like this

ClearControls(Page.Controls);



Approach2-

Use this code inside button click event:

Form.Controls.Clear();



Approach3-
Use this code inside button click event:

Page.Response.Redirect(Page.Request.Url.RawUrl)



Approach4-
Use this code to redirect to the same page

Response.Redirect(Request.Url.PathAndQuery, true);


这篇关于如何在提交表单后重置所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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