473,769 Members | 5,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default submit button

I am sure this question has been asked many times, however I am yet to find
a satisfactory solution to the problem. I have a number of user controls
within an asp.net page, a login box, a search box, and contact form. I wish
to be able to ensure that when the user presses enter in the appropriate
textbox control, the correct form is validated and submitted.

I have tried a number of methods to achieve this goal, the main one being
setting the __EVENTTARGET hidden form field value to the id of the button I
wish to be "clicked" when the enter key is pressed. I do this by adding an
onkeypress attribute to each of the textboxes within the usercontrol. This
doesn't appear to be working however, and one button is always "clicked"
rather than the others.

I wondered if anyone may have some advice on how to handle this approach
where there are several user controls which would each have been a form in
their own right in old style asp. Also I'd be interested in how people
would handle the validation of such a scenario, I am inclined to just write
my own validation routines for the scenario, rather than rely on the inbuilt
validation, which doesn't appear to work well for this.

I have also found it necessary to check each of the validators individually
within the user control to check if the data submitted IsValid, if I try to
call Page.IsValid then it will validate all of the validation controls
within the page, not just within the user control. Am I missing something
here or is there anyway to validate only the controls within the current
user control.

This would seem to be a fairly common situation, however I am finding it
very difficult to easily achieve the results I am looking for using ASP.Net.
Any thoughts appreciated....

Nov 17 '05 #1
1 3909
Matt,

Here's how I'm taking care of it:

TextBox.Attribu tes.Add("onkeyd own", "javascript:if( (event.which &&
event.which == 13) || (event.keyCode && event.keyCode ==
13)){document.F orm1." & Button.ClientID & ".click();retur n false;}else
return true;")
--
S. Justin Gengo, MCP
Web Developer / Programmer

Free Code Library At:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Matt Howeson" <ho*****@hotmai l.com> wrote in message
news:iM******** *************@s tones.force9.ne t...
I am sure this question has been asked many times, however I am yet to find a satisfactory solution to the problem. I have a number of user controls
within an asp.net page, a login box, a search box, and contact form. I wish to be able to ensure that when the user presses enter in the appropriate
textbox control, the correct form is validated and submitted.

I have tried a number of methods to achieve this goal, the main one being
setting the __EVENTTARGET hidden form field value to the id of the button I wish to be "clicked" when the enter key is pressed. I do this by adding an onkeypress attribute to each of the textboxes within the usercontrol. This doesn't appear to be working however, and one button is always "clicked"
rather than the others.

I wondered if anyone may have some advice on how to handle this approach
where there are several user controls which would each have been a form in
their own right in old style asp. Also I'd be interested in how people
would handle the validation of such a scenario, I am inclined to just write my own validation routines for the scenario, rather than rely on the inbuilt validation, which doesn't appear to work well for this.

I have also found it necessary to check each of the validators individually within the user control to check if the data submitted IsValid, if I try to call Page.IsValid then it will validate all of the validation controls
within the page, not just within the user control. Am I missing something
here or is there anyway to validate only the controls within the current
user control.

This would seem to be a fairly common situation, however I am finding it
very difficult to easily achieve the results I am looking for using ASP.Net. Any thoughts appreciated....

Nov 17 '05 #2

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

Similar topics

36
72086
by: spence | last post by:
Hi All How do I make it so that when a user clicks in a search text field, the default entry (in this case "Search") is removed automatically - they are then faced with a blank search box and can type straight away Thanks in advance
2
2612
by: Christopher Benson-Manica | last post by:
According to http://www.w3schools.com/tags/tag_button.asp, the type attribute of the <button> tag is optional. Is the UA at liberty to choose any type it wishes if the attribute is omitted? Does the presence or lack of a DTD impact the answer? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
2
2706
by: chris | last post by:
i have a form with 3 buttons with a text box next to each button what i want to do is when a textbox is filled out the default button is changed to the button next to that text box rather than the first button on the form. how would i do this. Chris
2
1596
by: Bratislav Jevtic | last post by:
hi, how to make some push button default on the form? for instance, I've got 2 buttons (Submit, Cancel). submit is on the left, cancel on the right side. on enter key pressed, cancel button is processed - wrong. so, how to make a button default (when one presses ENTER then it's processed onClick event)? thanks, bj
4
4901
by: RA | last post by:
Hi I have asp.net web app. When a user clicks the enter key when he is viewing the aspx web form, it jumps to the starting web form. How can I handle the user hitting the enter key and to redirect it to a default button. So lets say that I have a button name - Submit - if the user clicks anywhere in the form on the enter key I want it to default to a click on the 'Submit' button which is an asp.net button.
2
1743
by: Sanjeeb Sarangi | last post by:
I have got a couple of Serverside Button Controls in a page. Each button performs different actions, e.g. Button1 performs Submit, Button2 performs Cancel etc. Now, I want the default button mapped to the Enter key would be "Submit". I know a couple ways to achive this functionality using html buttons. But, how to achieve this functionality with Serverside buttons? Any idea Thanks in advance
1
977
by: Jason | last post by:
I know this is going to be a stupid question, but I'm in a crunch and don't have time to research it as much as I'd like. How do you tell the web form which button is the default button. So if a user fills out the form and hits enter instead of clicking the submit button, the correct button gets triggered. In other words I have a web form with a cancel button and a submit button and when I go into the form the and fill it out and hit...
3
1860
by: Xarky | last post by:
Hi, I have a page with 2 textboxes(Name and Surname) and two buttons(Submit and Reset). Now I have set the tab for them 1 Name 2 Surname 3 Submit 4 Reset
2
9836
by: AlecL | last post by:
Hi All, I have added a user control onto an aspx page and want to make the submit button of that user control the default button when the panel in which the user control is located is visible. I have used the code: Page.RegisterHiddenField("__EVENTTARGET", "Login.btnSubmit") in the Page Load event but this does not make the submit button default(enter) button. Any ideas on how can I do this. I have also tried using just the name of...
0
2783
by: thersitz | last post by:
Hi, Using aspnet3.5,VStudio 2008, VB 1.) I have a set of pages, with a search text box button within a userControl that searches across our websites and is registered in a masterpage. 2) Also within that set of pages, I have a second, distinct seach box and button that searches a specific database that is within an asp:content area
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10210
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
10043
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
9990
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
9861
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...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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...
1
3956
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

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.