Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

746 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

13 Experts available now in Live!

Get 1:1 Help Now