Solved

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

Posted on 2008-11-02
1
220 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

14 Experts available now in Live!

Get 1:1 Help Now