Change Validator’s ErrorMessage/Text ClientSide

In this post , I change CustomValidator’s errorMessage & Text values clientside. Here’s an example

<form id="form1" runat="server">
<div>
<script type="text/javascript">
   function CheckText(sender, args) {
     sender.errormessage = "Error Message Changed.";
     sender.innerHTML = "Text Changed";
     args.IsValid = false;
   }       
</script>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="ABC"  />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" Text="aa" ErrorMessage="*" ValidateEmptyText="true"  
Display="Dynamic" ControlToValidate="TextBox1"  ValidationGroup="ABC" ClientValidationFunction="CheckText">
</asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" 
       ValidationGroup="Background" onclick="Button1_Click" />
</div>
</form>

Advertisements
This entry was posted in General ASP.Net C#. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s