473,322 Members | 1,562 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,322 software developers and data experts.

RegisterHiddenField to Capture Enter Resetting Application

Hi - I wanted to capture the enter button on a form since I have a
datagrid with the first column being a delete button and if someone hits
enter it deletes the first record. I coded:

private void Page_Load(object sender, System.EventArgs e)
{
Page.RegisterHiddenField("__EVENTTARGET","SomeButt onOnThePage");
Nov 17 '05 #1
1 3063
Hello Matthew,

If we have multiple buttons on a webform, the first one rendered in the browser will fire when you press the Enter button.

In this scenario, you need to add attributes to textboxes in the Page_Load event to check which Button_click event to fire.

txtText1.Attributes("OnKeypress") = "return KeyPressFunction('button1')"
txtText2.Attributes("OnKeypress") = "return KeyPressFunction('button2')"

Then add the following code in the .aspx page

<script language="javascript">
function KeyPressFunction(buttonName)
{
if (event.keyCode == 13)
{
if (buttonName == "button1")
{
Form1.button1.click();
return false;
}

if (buttonName == "button2")
{
Form1.button2.click();
return false;
}
}
}
</script>

Summary: If you are typing in txtText1 and hit Enter, button1_click event will fire, If you are typing in txtText2 and hit Enter,
button2_click event will fire...regardless of what other buttons are on the page.

Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Message-ID: <3F**************@SatoriGroupInc.com>
!Date: Fri, 18 Jul 2003 09:08:18 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!Subject: RegisterHiddenField to Capture Enter Resetting Application
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:160248
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hi - I wanted to capture the enter button on a form since I have a
!datagrid with the first column being a delete button and if someone hits
!enter it deletes the first record. I coded:
!
!private void Page_Load(object sender, System.EventArgs e)
!{
! Page.RegisterHiddenField("__EVENTTARGET","SomeButt onOnThePage");
! .
! .
!
!but now when I hit enter it goes back to the first web page in the
!application! Does anyone know either what is causing this behaviour, or
!how I can just "eat" the enter button so it doesn't do anything?
!thanks!
!
!
Nov 17 '05 #2

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

Similar topics

4
by: Erik Cruz | last post by:
Hi. I am creating a custom control that uses the RegisterHiddenField method to insert a hidden field on a page. When I tried to see the value of the hidden field on a trace, I noticed that it...
0
by: Francis | last post by:
Hi all, I am writing a .cs component that sets RegisterHiddenField on the server side and generates javascript to execute on the client side. It works when the component is directly in the...
0
by: Dave | last post by:
Are there any known restrictions on where Page.RegisterHiddenField will work? It seems to only work in the Page_Load event...My code below fails to render it in the page's source I would like...
1
by: Pete Mahoney | last post by:
I have a datagrid with a button column that displays some partner info. i.e. PartnerId, PartnerName ... The button column has a button that when the user clicks it they are redirected or...
2
by: ashish | last post by:
If i want to add a hidden field on the page, how can i check whether that hidden field exists ? for example if i do If Page.FindControl("myhiddenfield") Is Nothing Then...
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...
3
by: John Smith | last post by:
I am having a brain fart today.... How do you set a default button within a User Control? I am using "Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit")" but it does not seem to be working...
7
by: Bob Achgill | last post by:
When I use the code for KeyPress to capture pressing a certain key for processing on a form with no Text Box it works. But when I try the same code on my application that has text boxes it does...
3
by: Melson | last post by:
hi can anyone help me how can i capture ENTER keystroke when the cell in datagrid is in editing mode. I'm now creating a data entry form with primary key in header and details in datagrid. So...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.