How to make Enter key fire ASP:Button event for DropDownList control after an autopostback?

Posted on 2006-04-10
Last Modified: 2012-08-13
I would like to use the Enter key to act as though a Find button was pressed. I have no problem doing this if the last field the user typed in is a text field. However, I have many DropDownList controls and I want to be able to have the user select an item from the drop-list and press Enter and have the Find button fire. Again this works just fine if the DropDownList does not have autopostback set to true. If autopostback is set to true the Enter key does nothing. If I again select the same item from the drop-list (which means the post back does not happen as it is the same item) the Enter key does act as the Find button. The Find button is an Asp:Button type. My question - How do I make the Enter key work for a DropDownList control that has posted back immediately after the post back? Thanks - David
Question by:dloendorf
    LVL 2

    Expert Comment

    add the following in the command of your DropDownList control post back and see if this help, or you may try to add the javascript in the attribute of body onload in the command of your DropDownList control post back if it's not working, and remove it inside the Find_Button poastback command,

    string SCRIPT = "<script type=\"text/javascript\">";
    SCRIPT += this.GetPostBackEventReference(this.your_findButton);
    SCRIPT += "</script>";

    if (!Page.IsStartupScriptRegistered("Find")
          Page.RegisterStartupScript("Find", SCRIPT);
    LVL 2

    Accepted Solution

    Hello dloendorf,
                I am very sorry to say this but if you have a dropdownlist then you cannot make the enter key event to be fired for a default button unless the ficus is out of the dropdownlist.

              Microsoft still are working on it.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now