473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Control postback events when enter key is pressed

This is one of those problems that should be easy but isn't turning out
that way: There are two textboxes on a page, each associated with a
button which has a Click event to do something different.

What happens when the user presses the Enter key?

I want one of the event handlers to be fired in this situation. The
only solution I have for this is not pretty: To use a flag to check if
the event has been fired from the Page_Load event handler.

bool calledByEnterKey= false;
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
btnSearch_Click(new Object(), new System.EventArgs());
calledByEnterKey==true;
}
}

This calls my click event for all postbacks. The event then must check
the boolean property calledByEnterKey to make sure it doesn't run
twice:

private void btnSearch_Click(object sender, System.EventArgs e)
{
if (!calledByEnterKey)
{
//do something
}
}

This works, but it's not the clear, elegant solution that I would like.
There must be a better way!

Nov 18 '05 #1
0 912

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RTM | last post by:
Can anyone help me with the following issue? I've seen some similar questions here, but none relating to a textbox control.... I have a form with several controls, one of them being a textbox...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
1
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click...
5
by: getdotnet | last post by:
hello, I am using a form which has multiple buttons(asp server controls) say B1, B2 and B3. The postabck gets fired on B1 click whereas I want it to happen on B3 click. I know that by default the...
3
by: Steve | last post by:
Hi, I want to determine which key was pressed in a control, like a datagrid. I see that in the currentcellchanged event of a datagrid I can capture keystroke events. I have tried someting...
3
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the...
6
by: John Smith | last post by:
How can I find out which control performed PostBack? I have put this code inside my Page_Load event: Response.Write(Page.Request.Params.Get("__EVENTTARGET")) but it doesn't write to response...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
1
by: Dan Bass | last post by:
I'm developing an Ajax keypad (C# / ASP.Net 3.5 / VS 2008) using the updatepanel so that a full visible postback doesn't occur with each button press. I've decided to try and wrap the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.