Using an ASP.NET application I have a Textbox as:
<asp:TextBox ID="NEEDID" runat="server" MaxLength="50" ></asp:TextBox></div>
<asp:RegularExpressionValidator ID="AdvNeedIdValidator" runat="server"
ControlToValidate="NEEDID" ErrorMessage="Need ID is numeric."
ForeColor="Red" ValidationExpression="^\d*\.?\d*$">*</asp:RegularExpressionValidator>
and two buttons for Search
and Clear Search
for c;earing search box.
<asp:Button ID="Adv_SearchButton" runat="server" Text="Search" ClientIDMode="Static" OnClick="Adv_SearchButton_Click"/>
<asp:Button ID="ClearFilterButton" ClientIDMode="Static" CssClass="thin-button" runat="server" Text="Clear Search" onclick="ClearFilterButton_Click" />
now my problem is even on clearing the search box the ValidationExpression
is functioning! while it is suppose to only run when the Search
button clicks! Can you please let me know how to fix this?
Thanks
Add the attribute CausesValidation="false"
to your clear button. Since your button causes a postback, it is going to validate the content of the TextBox
.
Better still, consider using Javascript to clear the content of the TextBox
to improve the user experience by avoiding the postback to your server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.