Introduction
Here I will explain how to change the error message of custom validator dynamically using asp.net.
Description
I have one textbox, one button and one custom validator to validate the textbox whenever user clicks on button.
In customvalidator I have taken ClientValidationFunction="ClientValidationFunction" this clientside function is used to send error message dynamically by using sender object. This sender object will display ErrorMessage dynamically.
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function ClientValidationFunction(sender, e) { var errorMessage = "'" + e.Value + "' is not a good value."; sender.innerText = errorMessage; sender.errormessage = errorMessage; e.IsValid = false; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidationFunction" ControlToValidate="TextBox1" ErrorMessage="CustomValidator"></asp:CustomValidator> </div> </form> </body> </html> |
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
nmb
Note: Only a member of this blog may post a comment.