Reputation: 57
Is there a way to show the error message of customValidator without POSTBACK?
I have used both requiredFieldValidator and customValidator. The fomer can be inline and can show error message without postback. Is this possible for customValidator?
Upvotes: 0
Views: 1214
Reputation: 6967
Option 1 :
Whenever I create a custom validator, I try to create a server and client side validation methods to validate. creating a client side method will avoid unnecessary postback. As a safety measure, server side method should be present.
Example :
<asp:Textbox id="text1" runat="server" text=""></asp:Textbox>
<asp:CustomValidator id="CustomValidator2" runat="server"
ControlToValidate = "text1"
ErrorMessage = "You must enter at least 8 characters!"
ClientValidationFunction="validateLength" >
</asp:CustomValidator>
<script type="text/javascript">
function validateLength(oSrc, args){
args.IsValid = (args.Value.length >= 8);
}
</script>
Option 2:
It is not always possible to build a client side validation method. There you can use update panel to hide those postbacks.
Upvotes: 1
Reputation: 9414
you can use Update Panel ajax to this action without postback.
Upvotes: 1