I have a page with a drop-down list (Telerik RadComboBox) control to validate.
I have put a CustomValidator to verify that the user has selected something from the list. Then there is a LinkButton to submit the selection.
This is the CustomValidator:
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ClientValidationFunction="validateCombo" ValidateEmptyText="true"
ErrorMessage="You must select an item with even value"
ValidationGroup="defGroup">
this is the LinkButton:
<asp:LinkButton ID="LnkInsertOrder" runat="server" Text="Inserisci Ordine" OnClick="LnkInsertOrder_Click" CausesValidation="true" ValidationGroup="defGroup" CssClass="btn btn-lg btn-info"> </asp:LinkButton>
and here is the client side function I'm using for test:
function validateCombo(source, args) {
alert('validateCombo'); //is never shown!
args.IsValid = false; //fake validation...
}
validateCombo is never called, as I never see the alert, and even if I try to call manually from the js console the .net framework function Page_ClientValidate("defGroup"), it always returns true, and the alert is not shown.
When I press the link button it performs a postback and the property Page.isValid is true.
I'm trying to stop the postback when the user press the link button if all the validators of the defGroup validation group are not valid.
Discovered that also Page_Validators list on the client is empty (it should contain all the asp.net validators), and it has guide me to the "solution": .net 4.5 has an 'incompatibility' of some kind when you put a ScriptManager and you use also jQuery >1.9... or maybe I have to add the js libs using ScriptResourceMapping in Global.asax
BTW to fix it, simply use the old validation style adding a key setting in web.config:
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
it sounds crazy to me, but when I've added this line everything has started to work