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 9121391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:51:07+00:00 2026-06-17T05:51:07+00:00

here’s a dropdownlist that posts back on selected index changed. <asp:DropDownList ID=_ddlClientType runat=server AutoPostBack

  • 0

here’s a dropdownlist that posts back on selected index changed.

<asp:DropDownList ID="_ddlClientType" runat="server"  AutoPostBack = "true"
   OnSelectedIndexChanged="ClientType_SelectedIndexChanged"  >                                 
   <asp:ListItem Value="-1" Text="CANCEL.."></asp:ListItem>
   <asp:ListItem Value="11" Text="External"></asp:ListItem>
   <asp:ListItem Value="12" Text="Internal"></asp:ListItem>
   <asp:ListItem Value="13" Text="TOM"></asp:ListItem>
</asp:DropDownList>   

When using the mouse, everything works perfectly. However, I want user to be able to press key to select different items either by by using up/down arrow key. Also when when user type a letter, then the first item starting with that letter gets highlighted.

The problem is when a different item gets selected in the dropdownlist, the page posts back because of the “OnSelectedIndexChanged” event.

Is there a way to prevent the postback to occur when key are being pressed (as opposed to mouse being clicked), until the enter key is pressed?

EDIT

I’m able to display the alert prompt when a key is pressed

$('select').keypress(function () {
  alert('A key was pressed')
});

Now, I need to know which key was pressed. Thus, I’ll be able to make a decision.

  • 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-06-17T05:51:08+00:00Added an answer on June 17, 2026 at 5:51 am

    There is a bit of a mistake in your question:

    The problem is when a different item gets selected in the dropdownlist, the page posts back because of the "OnSelectedIndexChanged" event.

    The page is actually posting back because of AutoPostBack = "true".

    First change AutoPostBack to False.

    Then I would suggest that you handle the change event and the keypress event differently. If you handle the change event using jQuery and then submit inside that change event and also handle the keydown and filter for keys then you can submit only when you want to.

    $("#TargetSelect").change(function(event){
        console.debug($(this).val());
    });
    $("#TargetSelect").keydown(function(event){
        event.preventDefault();
      if(event.which == 13){
         $(this).trigger('change');
      }else if(event.which == 38){
        var idx = this.selectedIndex;
        if(idx != 0){
          $("#TargetSelect").prop('selectedIndex', idx-1); 
        }
      }else if(event.which == 40){
        var idx = this.selectedIndex;
        var maxIndex = $('select').children('option').length;
        idx += 1;           
        if(idx < maxIndex){
          $("#TargetSelect").prop('selectedIndex', idx); 
        }
      }else{
          var $options = $('select').children('option');
          $options.each(function(){
            if(String.fromCharCode(event.which) == $(this).text().charAt(0)){
              var idx = $(this).index();
              $("#TargetSelect").prop('selectedIndex', idx);     
            }
          });
        }
    });
    

    Here is an (updated) example. Replace the console.debug with submit of the form and you should be golden.

    If you have multiple select boxes the code should be as follows:

    $("select").change(function(event){
        console.debug($(this).val());
    });
    $("select").keydown(function(event){
        event.preventDefault();
      if(event.which == 13){
         $(this).trigger('change');
      }else if(event.which == 38){
        var idx = this.selectedIndex;
        if(idx != 0){
          $(this).prop('selectedIndex', idx-1); 
        }
      }else if(event.which == 40){
        var idx = this.selectedIndex;
        var maxIndex = $(this).children('option').length;
        idx += 1;           
        if(idx < maxIndex){
          $(this).prop('selectedIndex', idx); 
        }
      }else{
          var $options = $(this).children('option');
          var $thisSelect = $(this);
          $options.each(function(){
            if(String.fromCharCode(event.which) == $(this).text().charAt(0)){
              var idx = $(this).index();
              $thisSelect.prop('selectedIndex', idx);     
            }
          });
        }
    });
    

    Also be aware that if you have two entries that start with the letter typed, then you will select the last entry. A modification could be made to the code to allow for the box to be filtered.

    Example for multiple boxes

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

Sidebar

Related Questions

Here's the setup - I have a view that lists products. On that same
Here's the link: www.mchenry.edu/maps/google.asp Why won't the location balloon display correctly? Also, the pop-up
Here is a scenario: User installs .NET application that you have made. After some
Here's a sample of a SpinBox that writes its changes to underlying variables. The
Here is my code for the POST request to the server. The JSON to
Here is my scenario. I have a website running under AppPool1 and that works
Here's the code I have. It works. The only problem is that the first
Here's the scenario: I have a local git repository that mirrors the contents of
Here's the problem....I have three components...A Page that contains a User Control and a
Here's my situation. I've noticed that code gets harder to maintain when you keep

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.