473,761 Members | 10,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegisterHiddenF ield 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(objec t sender, System.EventArg s e)
{
Page.RegisterHi ddenField("__EV ENTTARGET","Som eButtonOnThePag e");
Nov 17 '05 #1
1 3093
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.Attrib utes("OnKeypres s") = "return KeyPressFunctio n('button1')"
txtText2.Attrib utes("OnKeypres s") = "return KeyPressFunctio n('button2')"

Then add the following code in the .aspx page

<script language="javas cript">
function KeyPressFunctio n(buttonName)
{
if (event.keyCode == 13)
{
if (buttonName == "button1")
{
Form1.button1.c lick();
return false;
}

if (buttonName == "button2")
{
Form1.button2.c lick();
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...regardle ss 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************ **@SatoriGroupI nc.com>
!Date: Fri, 18 Jul 2003 09:08:18 -0400
!From: Matthew Wieder <De*********@Sa toriGroupInc.co m>
!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: RegisterHiddenF ield to Capture Enter Resetting Application
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1602 48
!X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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(objec t sender, System.EventArg s e)
!{
! Page.RegisterHi ddenField("__EV ENTTARGET","Som eButtonOnThePag e");
! .
! .
!
!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
1798
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 does not appear on the Control Tree section of the trace. I put a normal hidden field on an aspx page and set it to run as a server control, and the control appears at the trace info. I have two questions about this: 1) Only server controls can...
0
1487
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 page, but not when it is inside an ascx. In the source code of the page, I can see that the ascx adds an prefix before the ID of the hidden field. This kind of thing is no problem when you are using javascript on objects such as buttons, that have a...
0
2697
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 these values to be used by some client-side javascript. If I can't use the register methods here, how can I make the data grid's clicked values availble in the Page_Load's Postback? Thanks, Dave private void dgGrid_ItemCommand(Object src,...
1
2438
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 server.transfer to a different page where I would like to pass the PartnerId. I could do this very easy with a QueryString, but would rather not display this info in the URL. I want to pass this by creating a form variable using the...
2
5372
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 Page.RegisterHiddenField("myhiddenfield", "hidden") End If
5
3134
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 click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the first button, so when the user hits enter, the previous page is served up. Enter should result in...
3
1582
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 for me. I have another User Control which uses this technique and works. Can't think of what I am missing? --
7
62048
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 does not work. How can I capture the cursor left and right keys for processing?
3
13897
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 when user key in the details in datagrid, I would like user to choose product code by pressing ENTER key in the datagrid and a Product Code dialog will appear for him to choose.
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
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 we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.