GRRR! Pages submitting with Enter key, combined with .ASCX pages - help!
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.
the enter key in a text box, which works great... EXCEPT NOW, IF YOU
HIT ENTER JUST WITH FOCUS ON THE BROWSER, IT STILL SUBMITS!!! And the
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?
|All times are GMT. The time now is 12:33 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.