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

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 3874
Matt,

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

TextBox.Attributes.Add("onkeydown", "javascript:if((event.which &&
event.which == 13) || (event.keyCode && event.keyCode ==
13)){document.Form1." & Button.ClientID & ".click();return 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*****@hotmail.com> wrote in message
news:iM*********************@stones.force9.net...
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
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...
2
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...
2
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...
2
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...
4
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...
2
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...
1
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...
3
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
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. ...
0
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)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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...
0
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...

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.