Link to home
Start Free TrialLog in
Avatar of dloendorf
dloendorf

asked on

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

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
Avatar of faifai
faifai

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);
      
ASKER CERTIFIED SOLUTION
Avatar of manojkumarps
manojkumarps

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial