Auto Ad Code

Thursday, June 17, 2010

Making a default button (For Enter Key)

Let me explain this using an example.
One makes a login page. Places "Login" and "Cancel" buttons below "User name" and "Password" Text boxes. He expects that whenever he will be pressing the Enter key while typing in User name or the password text box the "Login" button will be clicked, but sometimes this doesn't happen. Either Cancel gets clicked or any other button from page get clicked. Frustrated? Ok here is the solution for this

For this use an ASP Panel, place all controls withing that panel (don't worry this panel will not disturb the formatting of your page) and set the default button property of that panel to whatever button you want to be clicked whenever Enter key will be pressed.

For Example

<asp:panel runat="server" id="pnlMain" defaultbutton="btnSave">
<!-- All of your controls here -->
</asp:panel>


Now whenever one will press enter in any text box written in between the panel then btnSave will be clicked by default.

No comments:

Post a Comment