473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to Capture Click Event of Button While Pressing Enter Key From Textbox ?

26 New Member
Hi ! All,

I want to developed simple web page using asp.net 2.0
& C#. This web page page contain one text box & two
button just like a page of google. Assume that text of Button
is First & Second. I want to Provide a functionality that once
i type anything in text box & press enter key then First button
is invoke & whatever text typed in text box is display in
message box. If u have any idea then guide me.

Thanks in advance
Feb 20 '09 #1
2 4833
alamodgal
38 New Member
hi
you can use panel in your page and set its default button property to id of your button which u want to press first.Just like this example:

Expand|Select|Wrap|Line Numbers
  1.  <asp:Panel ID="panel1" runat="server" DefaultButton="first">
  2.     <asp:TextBox ID="name" runat="server"></asp:TextBox>
  3.     <asp:Button ID ="first" runat="server" text="First"/>
  4.     <asp:Button id="second" runat="server" Text="Second"></asp:Button>
  5.   </asp:Panel>

And then onclick event of your button show msgbox like this:

Expand|Select|Wrap|Line Numbers
  1.  Protected Sub first_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles first.Click
  2.         MsgBox("hello")
  3.  
  4.     End Sub
Feb 20 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Alamodgal's suggestion's correct.
The default button property is a very useful feature that can be used to solve your problem.

Just be aware that MsgBox("My message") will not work in an ASP.NET application.
Instead you should have some sort of control (like a Label, or Literal or something) on the page that you can set the text for.

For example, you'd have to add a Label to the Panel:
Expand|Select|Wrap|Line Numbers
  1. <asp:Panel ID="panel1" runat="server" DefaultButton="first">
  2.     <asp:TextBox ID="name" runat="server"></asp:TextBox>
  3.     <asp:Button ID ="first" runat="server" text="First"/>
  4.     <asp:Button id="second" runat="server" Text="Second"></asp:Button> 
  5.     <asp:Label id="myMessage" runat="server"></asp:Label>
  6.   </asp:Panel>
And you would set the Label's Text when the button is clicked in the Button Click Event to display which button was clicked:
Expand|Select|Wrap|Line Numbers
  1. protected void first_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  2. {
  3.    myMessage.Text = "First Button Clicked";
  4. }
Feb 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: REIVILONOSSALG | last post by:
How to prevent that the Button_Click event comes if one pressed Enter on TextBox which has a valid event handler Thanks for your response
5
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
5
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's...
12
by: SJ | last post by:
Hope someone can help me out there I'm struggling with a particular problem... I have a form with many tab pages. On one tab page I've got a button which when clicked with a mouse adds items...
8
by: Ken Sturgeon | last post by:
I have a button inside a panel control. Apparently I can't expect VB to respond to the button's _Click event. How do I capture the click event? Thanks Ken
3
by: Robert W. | last post by:
I'm new to ASP.net programming so excuse my ignorance if the following question seems overly simplistic. I've created a simple Login form with 3 primary WebControls: - A TextBox for the Username...
1
by: Joey | last post by:
I have an asp.net 1.1/C# web form with a text box server control and one button server control. Users can type in text to search and then click the button to start the search. I want them to be...
3
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I have two sets of search criteria on my page. They are placed inside two DIV tags made visible/hidden by a client script. In each DIV tag I have a LinkButton that performs the search from each...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.