By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,549 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,549 IT Pros & Developers. It's quick & easy.

GRRR! Pages submitting with Enter key, combined with .ASCX pages - help!

P: n/a
Totally hacked off here. I've written a user control that contains a
text box, a required field validator and a button (these being the
cornerstone of a search facility), all as ASP.Net server controls. The
user clicks the button, and server-side code does a redirect to a
search page, appending the search expression to the URL.

Great, I thought, let's move on. I then wrote an mailing list page
which included the aforementioned user control, then another textbox,
required field validator and button.

So, I load up the page, click the "Submit Email Addy" button - and the
search button required field validator kicks in. After research (on
Google Groups, natch), I figure out that it forms part of the page.
So, I disable the required field validator and it's viewstateenabled
properties. Then, when the user clicks the button, I re-enable the req
field validator, call Page.Validate(), and continue if things are ok.

This, when applied to my buttons and text boxes appeared to work - but
only if the buttons are clicked!!! If someone hits enter whilst in the
text box, the page submits, which is not desired. I've written a page
that, er, pages data with next/prev buttons. These buttons have their
viewstate disabled so I can enable them each time the page loads. So,
when the user hits enter in the text box, the whole page submits (the
validator code doesn't get fired) and the prev\next buttons are
disabled because that's their initial setting.

After yet more research, I found some javascript code that disables
the enter key in a text box, which works great... EXCEPT NOW, IF YOU
search required field validator kicks in, which it most definitely
shouldn't (unless it's being picked up as the first "submit" button in
the page, yeah, that'd be it).

So, as just alluded to, I did more research and found out about
ASP.Net rendering ASP:button down to an <input type="submit"> control
and that reacts to a Enter keystroke because it's on a form.

In a nutshell: how do I a) stop the page from submitting JUST BY THE
USER HITTING ENTER and b) have separate textboxes, req. field
validators and buttons that act independently of each other?

Oh yeah: All by server-side stuff, no Javascript...


Mike Kingscott
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.