2

I have the following setup, where I am custom validating a textbox. It works fine as long as I am manually typing in the textbox and changing the text and focusing out of the textbox.

<asp:TextBox ID="tbpCity" runat="server"/>     
<asp:CustomValidator ID="cvPermanentCity" runat="server" ControlToValidate="tbpCity" 
 ErrorMessage="CustomValidator" onservervalidate="Field_ServerValidate"   SetFocusOnError="true" Display="Dynamic" ToolTip="PermanentCity" />
 <ajaxtoolkitwcsfextensions:ServerSideValidationExtender ID="PermanentCityServerSideValidationExtender" runat="server" TargetControlID="cvPermanentCity" />

when I try to invoke validation change event from javascript (using JQuery 1.4.2)

function copyCity() {
$('#<%= tbpCity.ClientID%>').value = "Some City";
$('#<%= tbpCity.ClientID%>').trigger("change");
}

the custom validation is not being invoked.

How can I inovke customvalidator to do validation?

note: I have verified this works on FireFox but not on IE. Please let me know how to fire change event in IE.

1 Answer 1

1

I have found the answer posted to similar question on StackOverflow.

var tbPermanentAddressCity = document.getElementById('<%= tbpCity.ClientID%>');
if (tbPermanentAddressCity.fireEvent) {
    tbPermanentAddressCity.fireEvent("onchange");
} else {
    $('#<%= tbpCity.ClientID%>').change();
}

Once the onchange event is fired, the CustomValidator picks up and validates the textbox.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.