I want to validate a WebCombo on the client side using a custom validator. Validating that a dropdown selection has been made after the "Go" button is selected. Which means that I want to load/activate the javascript function at the end of the last page event and before selecting the "Go" button.
JavaScript function:
function ComboCheck(sender, args){ var combo = igcmbo_getComboById('<%=wcPortName.ClientID %>').selectedIndex; if(selectedIndex == -1){ args.IsValid = false; } return args.IsValid; }
Validator:
<asp:CustomValidator id="validCustCombo" runat="server" CssClass="Text" ErrorMessage="Please make a selection in the dropdown!" ClientValidationFunction="ComboCheck"></asp:CustomValidator></TD>
If it were me, I would just put the validation when you hit the "Go" button.
<asp:Button ID="btnGo" runat="server" Text="Go" OnClientClick="Javacript: return Validate()" /> function Validate(){ var combo = igcmbo_getComboById('<%=wcPortName.ClientID %>').selectedIndex; if(selectedIndex == -1){ alert("Please Select something"); return false; } return true; }
<asp:Button ID="btnGo" runat="server" Text="Go" OnClientClick="Javacript: return Validate()" />
function Validate(){ var combo = igcmbo_getComboById('<%=wcPortName.ClientID %>').selectedIndex; if(selectedIndex == -1){
alert("Please Select something"); return false; } return true; }
Returning false will prevent the page from posting back and you can then either show the error message or do any other kinda of validation. ClientSide code will process before the server side. Of course, this option doesn't use your CustomValidator