Solved

Is There a way to fire the Click Event for a server Button Control with <ENTER> ??

Posted on 2008-11-02
1
222 Views
Last Modified: 2013-11-26
Greetings Experts!
I wonder if there is a way to accomplish what I have in mind, I hope someone could help me with  this. The Thing is, On one of my web pages (Default2.aspx), I have several server button  controls, <asp:Button runat=server>, and I have a textbox control, is there a way to fire the click event for one specific Button control when the user presses on the <ENTER> key on the keyboard??

Thanks in advannce.

~salman~
0
Comment
Question by:salman_sulaiman_2008
1 Comment
 
LVL 3

Accepted Solution

by:
dhanushkad earned 500 total points
ID: 22861403
Step 1 : Create a Panel (or use the Form object for the global Default Button) that will encompass both the object you want to apply the default action to (usually a Textbox) and the object that actually invokes the action (usually a Button, ImageButton or LinkButton) .

Step 2 : Create the Button object and make sure to give it both an ID and set the runat attribute to "server".

Step 3 : In the opening tag of the Panel , set the DefaultButton property to be the value of the ID property of your Button object.

Sample code :

<body>
    <form id="form1" runat="server" >
    <div>
        <asp:Panel ID="Panel1" runat="server" DefaultButton="btnOk">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            &nbsp;&nbsp;
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
            <asp:Button ID="btnOk" runat="server" Text="Ok" OnClick="btnOk_Click" />
          </asp:Panel>
     </div>
    </form>
</body>
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

776 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