.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to detect enter button pressed in private void button_click()

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :Windows Application

Hi, I am currently doing a project which control an external software using visual studio 2005. There is a button in the form. after I press the button, an external software will be opened. I am able to control it using mouseclick and sendkeys method. however, I need also to detect the enter button pressed by the user. Is there any idea??

For example

private void button1_Click( object sender, EventArgse)


    if(enter button pressed by user)





what can I write in the If statement?? Or I need to put other command in order to detect the enter button pressed??





View Complete Post

More Related Resource Links

detect enter keypress and trigger button click (all browsers)


I have some textbox's that when the enter key is pressed on them, i should fire a buttons action (say the go button).

Seems that it no longer works accross current browsers and  i was wondering if anyone has some nice javascript or something to detect if enter is pressed and fire a button click action (accross all current browsers - ie8, ff, safari, chrome etc)

change tab index by pressing enter button widthout postback

hi .  i have 3 textbox :<asp:textbox id="textbox1" runat="server" text="01" ></asp:textbox><asp:textbox id="textbox2" runat="server" text="02" ></asp:textbox><asp:textbox id="textbox3" runat="server" text="03" ></asp:textbox>  how i can focus on textbox2 from textbox1 by pressing enter button (widthout postback)?

Is possible...? set enter key button for gridview footer template..

http://geekswithblogs.net/dotNETvinz/archive/2009/06/04/adding-dynamic-rows-in-gridview-with-textboxes.aspxI have used the above grid view in my application . Its working good, no problem. Upon clicking the Addnewrowbutton, it uses to create a new row dynamically. What i need is, new row should also be created dynamically, upon pressing enter key in the last textbox on a particular gird view row.  User always can't go and click addnewrowbutton every time to create new row. Instead of it, user can press enter in the last textbox on a particular grid view row to create new row. Hope you guys have understood. Please Note: Here I have used master page.

Auto-complete extender and default button of a panel - Enter key issues


Hi. I have a text box with an auto-complete extender attached to it. This is in a panel. Now, I have set the default button of the panel to the submit button of the panel.


      <text box/>




Now, I find that when the auto-complete options show up and I try to select an option using the enter key, the button is pressed (triggering a postback) due to it being the defaultbutton of the panel.

I want to be able to select an aut-complete option using the enter key and yet not post back. Therefore, the enter key (when the text box is in focus) should not trigger a postback. How can I achieve this?

Keeping a button pressed


hey everyone

I have a question about button behavior.

There is a left column with a stackpanel (vertical) and I've created a rectangle , changed some settings (what this guy did http://www.youtube.com/watch?v=6d6yWhWH4U4) .

Now I have the buttons and each behavior is ok, changed some colors in onmouseover and pressed.

I want to keep a button pressed once it has been clicked to view a panel. Kind of a tab control but the tabs are buttons.

Don't know if it makes sense or not, or if there is another way to get this done, I'm all ears.


Thanks in advance

kind regards




CustomValidator which button pressed


I am CustomValidator to vlidate some data.There are 3 static buttons and some dynamically creating buttons in that page.

I just need to check validation when I press the save button.For all other button click I do not want to call the validation.
How do I tell that in the Validation function?

<asp:CustomValidator ID="CustomValidator1" runat="server"
        ErrorMessage="CustomValidator" ControlToValidate="DropDownList1"
         ClientValidationFunction="MyCustomValidation" ></asp:CustomValidator>

 function MyCustomValidation(objSource, objArgs)

//Proceed if the control pressed is cmdSave button.

    var Specialty = document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].text;

    if (Specialty == "Select an option")
objArgs.IsValid = false;
objArgs.IsValid = true;


Button clicked event on hitting enter in any textbox




I have a WPF form with some element on it (textbox, datagrid, button...). I have an "OK" button which will handle the form when I click on it. How could I call that event handler on every "Enter"? I mean if I hit enter key in any of the form element I want to process everything like when I clicked on "OK" button.




Selecting Datagrid Row when Right mouse button is Pressed.


How can i select the datagrid row when i click the right mouse button. I need to show the context menu in the datagrid but i am able to generate the context menu but selected row i not changing.

How can i solve this issue.


Saugat K.C.

Disposing when hower AND CTRL is activated AND left mouse button is pressed ????


I want to let the user get rid of some designelements (PictureBoxes) on a form very fast.

This code can do it IF the user holds down the CTRL-key AND moves the mouse cursor over the designelements.

    private void signal_MouseHover(object sender, EventArgs e)
      Cursor.Current = Cursors.Hand;
      if (commonThings.ctrlActivated)

I have two problems witch I can't solve:

1) I want to secure wrong deleting of designelements by ALSO test that the LEFT-mouse key is pressed togather with CTRL (there is no "buttons" with the e !)

2) the Hover-event is a little delayed, so the deleting is in fact a little slow

How can this be done ?


Best regards KSor, Denmark

MVC2: Set default button for 'Enter' Key


I have the following code in a View:


            <% if ( Model.IsLoggedIn != true ) { %>
                <input class="NavButton" type="submit" name="submitButton" value="Previous" /> 
                <input class="NavButton" type="submit" name="submitButton" value="Login" /> 
            <% } %>

How do I set the "Login" button as the default button for when the "Enter" key is clicked on the keyboard?


Thank You ! 

Why nothing happens when PasswordRecovery submit button pressed?

<asp:PasswordRecovery runat="server" id="passwordrecovery" BackColor="white" BorderColor="#CCCC99" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="1em" QuestionLabelText="Question: In what city were you born?" QuestionLabelStyle="z-index:25" cssclass="square" UserNameInstructionText="To receive your password, first enter your User Name :" SuccessPageUrl="success.aspx">
	<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
		<table id="user" class="passwordrecovery" border="0" cellpadding="5" cellspacing="0" style="border-collapse:collapse;">
				<table border="0" cellpadding="16">
					<tr class="titlebar">
						<td align="center" colspan="2" class="titlespacing"></td>
						<td align="center" colspan="2" style="color:Black;font-style:italic;">
						To receive your password, first enter your User Name :</td>

C# Detect Key Combination Pressed



   How can I detect on my Form if the following key combination is pressed in sequence.

Hold ALT then 'P' then 'A' then 'U' then 'L'



How to set button_click and OnClientClick in single button


Say i have a button .

asp:Button ID="cmdGeneratePerforma" runat="server" OnClientClick="return check();"                                                            CausesValidation="true" Text="Generate Performa Invoice" CssClass="normaltext" onclick= cmdGeneratePerforma_click/>

is it possible to set button_click and OnClientClick in the same  button.if i want to use javascript validation for the form and also excute the code.

Problem to group radio button across gridview rows

In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

A Simple and Extensible Radio Button Style GridView

The GridView is one of the significant controls in ASP.NET 2.0 and later versions. No doubt it reduces a lot of work time. However, customizing the GridView control is not an easy task. For example, it's hard to add a radio button column to the GridView. This article demonstrates the reason why a radio button column cannot act as normal and how to create a simple and extensible radio button GridView.

How to detect and avoid memory and resources leaks in .NET application

Despite what a lot of people believe, it's easy to introduce memory and resources leaks in .NET applications. The Garbage Collector, or GC for close friends, is not a magician who would completely relieve you from taking care of your memory and resources consumption.

I'll explain in this article why memory leaks exist in .NET and how to avoid them. Don't worry, I won't focus here on the inner workings of the garbage collector and other advanced characteristics of memory and resources management in .NET.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend