Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 291303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:04:36+00:00 2026-05-12T06:04:36+00:00

I have a page where a user can either select a vendor via dropdown

  • 0

I have a page where a user can either select a vendor via dropdown or enter a vendor number via textbox. One or the other must have a value. I can do this in javascript easily but how can I do this using a custom validator provided by ajax all on the client side?

Edited

 Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    If Page.IsValid Then
        //save stuff
    End If
 End Sub

Sub ServerValidation(ByVal source As Object, ByVal args As ServerValidateEventArgs) Handles ValidPage.ServerValidate

     Try
         ' Test whether the value entered into the text box is even.
         Dim num As Integer = Integer.Parse(args.Value)
         args.IsValid = ((num Mod 2) = 0)

     Catch ex As Exception
         args.IsValid = False
End Try

End Sub

Protected Sub ValidPage_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
    Try
        args.IsValid = (Not String.IsNullOrEmpty(Me.txtVendnum.Text) OrElse Me.DropDownList1.SelectedIndex <> 0)
    Catch e As Exception
        DirectCast(source, CustomValidator).ErrorMessage = "You must Choose a Vendor"
        args.IsValid = False
    End Try
End Sub
<script type="text/javascript" language="javascript" >
   function ClientValidate(sender, args) {
       // Get Both form fields
       var ddlvalue = document.getElementById('<%=DropDownList1.ClientID%>');
       var txtValue = document.getElementById('<%=txtVendnum.ClientID %>');

    // do you client side check to make sure they have something
       if (txtValue.value == '' && ddlvalue.value == '0') {

        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }

}

<asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="SqlDataSource1" ValidationGroup="Save" DataTextField="vmvnnm" DataValueField="vmvend" >
                    </asp:DropDownList>

<asp:TextBox ID="txtVendnum" ValidationGroup="Save" runat="server"></asp:TextBox><br />

                        <asp:CustomValidator ID="ValidPage" ValidationGroup="Save" runat="server" ClientValidationFunction="ClientValidate" ErrorMessage="CustomValidator" 
                            SetFocusOnError="True" ControlToValidate="txtVendnum" EnableClientScript="true" Display="Static" OnServerValidate = "ServerValidation" ></asp:CustomValidator>

//other stuff. A different validator group, html editor, etc


<td>
                        <asp:ImageButton ID="ImageButton1" CausesValidation = "true"     ValidationGroup="Save" OnClick="ImageButton1_Click" runat="server" ImageUrl="../images/bttnSave.gif" />

                    </td>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:04:37+00:00Added an answer on May 12, 2026 at 6:04 am
    <asp:CustomValidator ID="ValidPage" runat="server" 
        EnableClientScript="true"
        ClientValidationFunction="My.util.VendnumCheck"
        OnServerValidate="ValidPage_ServerValidate"
        ControlToValidate="txtVendnum" 
        ErrorMessage="You must Choose a Vendor" 
        SetFocusOnError="True" 
        ValidationGroup="Save">
    </asp:CustomValidator>
    

    ClientValidationFunction=”My.util.VendnumCheck”

    You should also be doing Server Side validation!

    protected void ValidPage_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            args.IsValid = (!string.IsNullOrEmpty(this.txtVendnum.Text) || this.DropDownList1.SelectedIndex != 0);
        }
        catch (Exception e)
        {
            ((CustomValidator)source).ErrorMessage = "You must Choose a Vendor";
            args.IsValid = false;
        } 
    }
    
    
    protected void Button_Click(object sender, EventArgs e)
    {
         if (Page.IsValid)
         { 
             //do work
         }
    }
    

    JS:

    My.util.VendnumCheck = function(sender, args) {
    try {
            // Get Both form fields
            var ddlvalue = document.getElementById("<%=this.DropDownList1.ClientID %>");
            var txtValue = document.getElementById("<%=this.txtVendnum.ClientID %>").value;
    
            // do you client side check to make sure they have something 
            if ( txtValue.length < 1 && ddlvalue.selectedIndex != 0)
                args.IsValid = false;
    
            args.IsValid = true; 
        }
        catch (ex) {
            My.logError(ex);
            args.IsValid = false;
        }
    }
    

    try having this JS method called on Blur of the text box, see if it picks up the validator…

    My.util.callMyValidators = function() {
        // Clean Up Infragistics Ids
        var cleanid = this.id.replace(/^igtxt/i, "");
    
        if (Page_Validators == null) {
            alert("My.util.callMyValidators when Page_Validators is null");
        }
        var found = 0;
    
        for (var i = 0; i < Page_Validators.length; i++) {
            if (Page_Validators[i].controltovalidate === cleanid) {
                found++;
                ValidatorValidate(Page_Validators[i]);
            }
        }
    
        if (found === 0) {
            alert("My.util.callMyValidators did find any matching validators for " + cleanid);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page where a user can import data to the site. either
I have this PHP page where the user can select and un-select items. The
Background I have a payment page where the user can select from a list
I have a page where the user can dynamically add file upload boxes. Adding
I have a page where the user can edit various content using buttons and
I have a page where a user can upload a file along with some
I have a page which contains a dynamically generated grid, where a user can
I have a form on a page that a user can use to create
I have a section on a page where a user can change their username.
I have a list of items on my web page that the user can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.