Skip to content Skip to sidebar Skip to footer

User Control With Client + Server Side CustomValidation; Wrong Client Side Validator Is Picked

I have a user control which contains a CustomValidator which is used according to whether a RadioButton is checked or not (there are several RadioButtons, I'm only showing the rele

Solution 1:

Your client validation function is generated with the same name for both your user controls. There will be two ValidateDateFields_Client() functions in your page, and of course the interpreter will only call one of them.

One way to work around that problem would be to generate unique function names:

<script type="text/javascript">
function ValidateDateFields_Client_<%=RadioBetween.ClientID%>(source, args)
{
    // ...
}
</script>


<asp:CustomValidator ID="DateValidator" runat="server" Display="Dynamic"
    ClientValidationFunction="ValidateDateFields_Client_"
    OnServerValidate="ValidateDateFields"></asp:CustomValidator>


protected void Page_PreRender(object sender, EventArgs e)
{
    DateValidator.ClientValidationFunction += RadioBetween.ClientID;
}

Post a Comment for "User Control With Client + Server Side CustomValidation; Wrong Client Side Validator Is Picked"