Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to change the error message of custom validator dynamically using asp.net

Aug 22, 2010
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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Anonymous said...

nmb

Anonymous said...
This comment has been removed by a blog administrator.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.