Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Validate WebCombo Selected selectedIndex = -1 (newbe needs help!)
posted

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>

  1. First does the function look right?
  2. How do I call the code using VB (remember I am newbe). I only want to run the function when it calling it from the VB code (Like the click button handler)
Parents
No Data
Reply
  • 100
    Suggested Answer
    posted

    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;
      }

    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

     

     

     

Children