CustomValidator ClientSideFunction property isn't working with ValidationSummary control
-
I have a CustomValidator control which is declared like this:
<asp:CustomValidator ID="m_DelayCodeValidator" runat="server" ControlToValidate="m_DelayCode" Text="*" ErrorMessage="Delay code" EnableClientScript="true" ClientValidationFunction="m_DelayCode_Validate" OnServerValidate="m_DelayCode_Validate" />
I have a ValidationSummary control on the page as well. But when I try and submit the form the error message from my custom validator isn't listed with the other error messages in the ValidationSummary. The custom validation script isn't being called either - the script is only called when the value of ControlToValidate changes. I need the script called on submit as well like the other validators are. ValidationSummary:<asp:ValidationSummary ID="validationSummary" runat="server" DisplayMode="BulletList" HeaderText="Please enter the required values:" />
ClientValidationFunction:function m_DelayCode_Validate(sender, args) { if(m_DowntimeCode.options[m_DowntimeCode.selectedIndex].text != "Opportunity Maintenance") { args.IsValid = true; return; } if(args.Value == "" || args.Value == null || args.Value == undefined) args.IsValid = false; else args.IsValid = true; }
Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com
-
I have a CustomValidator control which is declared like this:
<asp:CustomValidator ID="m_DelayCodeValidator" runat="server" ControlToValidate="m_DelayCode" Text="*" ErrorMessage="Delay code" EnableClientScript="true" ClientValidationFunction="m_DelayCode_Validate" OnServerValidate="m_DelayCode_Validate" />
I have a ValidationSummary control on the page as well. But when I try and submit the form the error message from my custom validator isn't listed with the other error messages in the ValidationSummary. The custom validation script isn't being called either - the script is only called when the value of ControlToValidate changes. I need the script called on submit as well like the other validators are. ValidationSummary:<asp:ValidationSummary ID="validationSummary" runat="server" DisplayMode="BulletList" HeaderText="Please enter the required values:" />
ClientValidationFunction:function m_DelayCode_Validate(sender, args) { if(m_DowntimeCode.options[m_DowntimeCode.selectedIndex].text != "Opportunity Maintenance") { args.IsValid = true; return; } if(args.Value == "" || args.Value == null || args.Value == undefined) args.IsValid = false; else args.IsValid = true; }
Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com
I found the best thing is to dig in to the js that ASP.NET generates, and to write my own method that duplicates their calls but adds my own, if I want that degree of control.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
I found the best thing is to dig in to the js that ASP.NET generates, and to write my own method that duplicates their calls but adds my own, if I want that degree of control.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
Thanks for your suggestion. It led me to find a property I hadn't noticed as part of the CustomValidator control - ValidateEmptyText. Setting it to true fixes the problem for me. I guess I neglected to mention that the value of the default option was an empty string. I appreciate the help.
Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com
-
Thanks for your suggestion. It led me to find a property I hadn't noticed as part of the CustomValidator control - ValidateEmptyText. Setting it to true fixes the problem for me. I guess I neglected to mention that the value of the default option was an empty string. I appreciate the help.
Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com
Glad to help :-)
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.