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

  • Home
  • SEARCH
  • 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 6091043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:16:57+00:00 2026-05-23T12:16:57+00:00

Writing a custom validator for a dropdownlist that is using autopostback. Seems to ignore

  • 0

Writing a custom validator for a dropdownlist that is using autopostback. Seems to ignore the validation altogether. Why is it ignored and is there an easy fix?

Note I did not use ControlToValidate

asp.net:

     <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional" Visible="true" RenderMode="Inline">
        <ContentTemplate>
        <asp:DropDownList ID="ddlCommandAssign" runat="server" AutoPostBack="true">
        </asp:DropDownList>
          <asp:CustomValidator id="val_command_assigned" runat="server"  
          ErrorMessage="* " 
          display="Static"
          OnServerValidate="commandAssigned" 
          />
                </ContentTemplate>
       <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlCommandAssign" 
                EventName="SelectedIndexChanged" />
        </Triggers>

    </asp:UpdatePanel>

Behind Code:

Sub commandAssigned(ByVal source As Object, _
  ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)

    Dim s As String
    s = ddlCommandAssign.SelectedValue
    'if s = "1" then 
    '  args.IsValid = true
    'else
    '  args.IsValid = False
    'end if
    args.IsValid = False
End Sub

For debugging purposes, I want it to fail every time.

It doesn’t seem to be executing the behind code at all.

For debugging, I added the line response.redirect(“dummy.html”) … which never gets called, which also indicates (I think) that the validator never gets called.

  • 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-23T12:16:58+00:00Added an answer on May 23, 2026 at 12:16 pm

    Remove the update panel and try to do the validation at client-side itself using javascript.

    CLIENT-SIDE VALIDATION

    JavaScript event definition,

     function ValidateFunction(sender,args) 
     {
       var ddlCommandAssign= document.getElementById('<%=ddlCommandAssign.ClientID %>');
        if (ddlCommandAssign.options[control.selectedIndex].value=='0') 
        {  args.IsValid = false;//This shows the validation error message and stops execution at client side itself.}
      else { args.IsValid = true;//This will return to the server side. }    
     }
    

    Aspx section:

      <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="1">select</asp:ListItem>
            <asp:ListItem Value="2">sdasda</asp:ListItem>
        </asp:DropDownList>
        <asp:CustomValidator ID="valCustmID" runat="server" ErrorMessage="*" ForeColor="Red"
            ValidationGroup="group1" ClientValidationFunction="ValidateFunction"></asp:CustomValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="group1" />
    

    NOTE: Both the custom validator and the triggering button should have same validation group.

    SERVER-SIDE VALIDATION

    If you really want the validation server side see the code below:

         <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server">
                    <asp:ListItem Value="1">select</asp:ListItem>
                    <asp:ListItem Value="2">sdasda</asp:ListItem>
                </asp:DropDownList>
                <asp:CustomValidator ID="CustomValidator1" OnServerValidate="commandAssigned" runat="server" ErrorMessage="*" ValidationGroup="group1"></asp:CustomValidator>
                <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="group1" />
            </ContentTemplate>
        </asp:UpdatePanel>
    

    NOTE: Both the custom validator and the triggering button should have same validation group.

    code behind event looks as below:

        protected void commandAssigned(object source, ServerValidateEventArgs args)
        {
            if (DropDownList1.SelectedItem.Value == "1")            
                args.IsValid = false;  //since you gave controlToValidate="DropDownList1"  this will display the error message.       
            else           
                args.IsValid = true;            
        }
    

    Hope this helps..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a custom validator that checks that at least one field has a
I'm writing a custom validator that is going to check for the existence of
while writing a custom attribute in C# i was wondering if there are any
I am writing custom form validation javascript library and I am thinking about correct
I'll be tackling writing a custom date validation class tomorrow for a meeting app
I am writing a client-side validation function for CustomValidator and I need to check
When it comes to writing custom MySQL database-driven PHP session management for a VERY
When writing a custom server, what are the best practices or techniques to determine
When writing a custom channel how can I get the name of the service
I'm writing a custom file selection component. In my UI, first the user clicks

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.