CausesValidation=false不清空数据

本文关键字:清空 数据 false CausesValidation | 更新日期: 2023-09-27 18:05:32

我通常在我的web表单中使用CausesValidation=false,它工作,但它不工作在下面的表单。如果我输入一些数据,然后点击RESET按钮,所有必填字段(*)将消失;但是,它不会清除文本框或单选按钮中的信息。我试着添加Javascript OnClientClick="this.form.reset();return false;",仍然没有工作。我检查了一遍又一遍我的剧本,我在网上搜索,但我找不到一个解决方案。可以有两对<section></section>标签在同一个<面板>造成了问题?只是好奇。我注意到我之前的表单只有一对<section>在每个表单中标记;这是我第一次有两个部分。

<asp:Panel ID="submitPanel" runat="server" DefaultButton="submitBTN">
<section class="bg05 well04">
  <div class="container">
    <h2>Application for Enrollment</h2>
    <div class="columns">
    <div class="colLeft"><h4>Select Enrollment Type (select one):</h4></div>
    <div class="colRight">
    <asp:RadioButtonList ID="enrollType" runat="server" RepeatDirection="Horizontal" CssClass="spaced" ValidationGroup="submitApp">
        <asp:ListItem Value="Full-Time">Full-Time</asp:ListItem>
        <asp:ListItem Value="Part-Time">Part-Time</asp:ListItem>
    </asp:RadioButtonList><div class="colAdjust"><asp:RequiredFieldValidator ID="enrollRFV" runat="server" ControlToValidate="enrollType" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    </div>
    <br /><br /><br />
    <div class="colGeneral"><asp:Label ID="PriEmailLBL" runat="server" Text="<span class='format'>Primary email address:</span> "></asp:Label></div><div class="colGeneral1"><asp:TextBox ID="PriEmailTXTBOX" runat="server" Width="250px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="PriEmailRFV" runat="server" ControlToValidate="PriEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="PriEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="PriEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:'.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?'.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    </div>
  </div>
</section>
<section class="bg02 well02">
  <div class="container">
    <div style="margin-top: 10px;"></div>
    <h4 class="a">Member:</h4><br />
    <div class="colGeneral5"><asp:Label ID="CellLBL" runat="server" Text="<span style='color:White;margin-left:55px;'>Cell #:</span> "></asp:Label><asp:TextBox ID="CellTXTBOX" runat="server" Width="150px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="CellRFV" runat="server" ControlToValidate="CellTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    <br />
    <div class="colGeneral5"><asp:Label ID="SecEmailLBL" runat="server" Text="<span style='color:White;'>Secondary Email Address:</span> "></asp:Label><asp:TextBox ID="SecEmailTXTBOX" runat="server" Width="300px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="SecEmailRFV" runat="server" ControlToValidate="SecEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="SecEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="SecEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:'.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?'.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="White" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    <br /><br />
 <asp:Button ID="submitBTN" runat="server" Text="SUBMIT" OnClick="submitBTN_Click" ValidationGroup="submitApp" />&nbsp;&nbsp;
 <asp:Button ID="resetBTN" runat="server" Text="RESET" OnClientClick="this.form.reset();return false;" CausesValidation="false" ValidationGroup="submitApp" />
 <asp:Label ID="messageLBL" runat="server" Text="" Visible="false">/asp:Label>
 </div>
</section>
</asp:Panel>

CausesValidation=false不清空数据

在纠正标记并为resetBTN删除OnClientClick之后,它似乎具有所需的行为(当按下'reset'时形式被清除):

<asp:Panel ID="submitPanel" runat="server" DefaultButton="submitBTN">
<section class="bg05 well04">
  <div class="container">
    <h2>Application for Enrollment</h2>
    <div class="columns">
    <div class="colLeft"><h4>Select Enrollment Type (select one):</h4></div>
    <div class="colRight">
    <asp:RadioButtonList ID="enrollType" runat="server" RepeatDirection="Horizontal" CssClass="spaced" ValidationGroup="submitApp">
        <asp:ListItem Value="Full-Time">Full-Time</asp:ListItem>
        <asp:ListItem Value="Part-Time">Part-Time</asp:ListItem>
    </asp:RadioButtonList><div class="colAdjust"><asp:RequiredFieldValidator ID="enrollRFV" runat="server" ControlToValidate="enrollType" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    </div>
    <br /><br /><br />
    <div class="colGeneral"><asp:Label ID="PriEmailLBL" runat="server" Text="<span class='format'>Primary email address:</span> "></asp:Label></div><div class="colGeneral1"><asp:TextBox ID="PriEmailTXTBOX" runat="server" Width="250px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="PriEmailRFV" runat="server" ControlToValidate="PriEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="PriEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="PriEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:'.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?'.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    </div>
  </div>
</section>
<section class="bg02 well02">
  <div class="container">
    <div style="margin-top: 10px;"></div>
    <h4 class="a">Member:</h4><br />
    <div class="colGeneral5"><asp:Label ID="CellLBL" runat="server" Text="<span style='color:White;margin-left:55px;'>Cell #:</span> "></asp:Label><asp:TextBox ID="CellTXTBOX" runat="server" Width="150px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="CellRFV" runat="server" ControlToValidate="CellTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" ValidationGroup="submitApp"></asp:RequiredFieldValidator></div>
    <br />
    <div class="colGeneral5"><asp:Label ID="SecEmailLBL" runat="server" Text="<span style='color:White;'>Secondary Email Address:</span> "></asp:Label><asp:TextBox ID="SecEmailTXTBOX" runat="server" Width="300px" ValidationGroup="submitApp"></asp:TextBox><asp:RequiredFieldValidator ID="SecEmailRFV" runat="server" ControlToValidate="SecEmailTXTBOX" Font-Size="Medium" ErrorMessage=" *" ForeColor="Maroon" Display="Dynamic" ValidationGroup="submitApp"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="SecEmailREV" runat="server" ErrorMessage=" Invalid email address" ControlToValidate="SecEmailTXTBOX" ValidationExpression="[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+(?:'.[a-zA-Z0-9!#$%&'*+/=?^_`{}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?'.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" Font-Size="Medium" ForeColor="White" Display="Dynamic" ValidationGroup="submitApp"></asp:RegularExpressionValidator></div>
    <br /><br />
 <asp:Button ID="submitBTN" runat="server" Text="SUBMIT" OnClick="submitBTN_Click" ValidationGroup="submitApp" />&nbsp;&nbsp;
 <asp:Button ID="resetBTN" runat="server" Text="RESET" CausesValidation="false" ValidationGroup="submitApp" />
 <asp:Label ID="messageLBL" runat="server" Text="" Visible="false"></asp:Label>
 </div>
</section>
</asp:Panel>