Reputation: 4607
I am working on a donations website. The particular web page works by allowing the user to enter a monetary value in a textbox and clicking on the button 'Donate Now' to perform the transaction.
What I would like to do is to bring up a pop-up window with an error message if the user enters an invalid value in the textbox. How can this be done?
Upvotes: 0
Views: 1706
Reputation: 5616
Have you looked at the asp:RequiredFieldValidator
, asp:RegularExpressionValidator
and asp:ValidationSummary
features that asp.net provides?
Edit
Here is an example of a textbox which is only allowed to containt values on the form "xx-0000" (two letters, a '-', and then four digits). This is ensured by the RegularExpressionValidator
and the ValidationSummary
shows an popup with the error message if the textbox not containts a valid value.
<asp:TextBox runat="server" ID="txtContent" /><asp:Button runat="server" ID="btnOk" Text="OK" OnClick="btnOk_Click" />
<asp:RegularExpressionValidator runat="server" ID="txtContentValidator" ControlToValidate="txtContent" ValidationExpression="^[a-z]{2}-[0-9]{4}$" ErrorMessage="Not in the correct format" Display="Static" Text="*" />
<asp:ValidationSummary runat="server" ID="validationSummary" ShowMessageBox="true" ShowSummary="false" />
Upvotes: 3