【问题标题】:Reset a page in ASP.NET without postback在没有回发的情况下重置 ASP.NET 中的页面
【发布时间】:2014-07-03 08:44:33
【问题描述】:

我想重置表单,但每次单击重置按钮时,我都会使用一些“必填字段验证器”,错误消息显示需要字段...我尝试了什么:

ReuiqredFieldValidator.Enabled = false; 
TextBox.Text="";


Response.Redirect("Samepage.aspx");
Response.Redirect("Request.RawUrl");

<input type=reset>

【问题讨论】:

  • 为什么不试试 jquery?
  • 您是否尝试为重置按钮设置 CausesValidation=false。但在这种情况下,您必须将重置按钮设置为服务器控件。
  • @ZedBee 它解决了我的问题。很多 Thanxxx :)

标签: c# asp.net .net reset requiredfieldvalidator


【解决方案1】:

试试这个:

<asp:Button 
runat="server" 
ID="reBt" 
Text="Reset" 
OnClientClick="this.form.reset();return false;" 
CausesValidation="false"
/>

来自here

【讨论】:

    【解决方案2】:

    您可以将ValidationGroup 属性应用于控件组和相关的asp button,并且不要将ValidationGroup 提供给重置按钮。

    反之亦然

    这适用于您使用 asp.net 控件

    参考这个link

    【讨论】:

      【解决方案3】:

      你可以试试

      <input type="reset" causesvalidation="False">
      

      它应该工作。
      它适用于input submit,所以我认为它也应该适用于input reset

      详情Input =submit

      编辑 1

      或者如果你使用 jQuery,你可以像这样使用

      $(':input','#myform')
       .not(':button, :submit, :reset, :hidden')
       .val('')
       .removeAttr('checked')
       .removeAttr('selected');
      

      参考

      1. Clear form fields with jQuery
      2. How to reset a form using jQuery with .reset() method

      jQuery 参考

      :reset Selector

      【讨论】:

      • @majidgeek 访问这是针对 .net framework 4.5 link
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      相关资源
      最近更新 更多