Two text boxes each with their own button

G

Greg

I have a big problem. I have two text boxes each with their own own button.
Buton1 is for Textbox1 and Button2 is for Textbox2. Here's the problem, if
someone enters something into Textbox1, then enters something into Textbox2,
then hits their return key Button1 is called not Button2. This also happens
if they press Button2... Button1 is still called. Now, if they don't enter
anything into Textbox1 then Button2 is called when they enter something into
Textbox2 and hit return or press Button2.

Both textboxes have postback off (I also tried with on but that caused it to
submit twice).

Is there away around this or am I supposed to figure out some javascript to
empty Textbox1 when someone clicks on Textbox2?
 
C

Curt_C [MVP]

1) catch the button click in the code-behind instead of using the page_load
with an IsPostBack
2) use clientside code to catch the textbox's key_down event, specifying the
enter key, and have it "push" the appropriate button.

I'm sure there are other ideas, those are just the first two I had.
 
G

Greg

Curt_C said:
1) catch the button click in the code-behind instead of using the page_load
with an IsPostBack
2) use clientside code to catch the textbox's key_down event, specifying the
enter key, and have it "push" the appropriate button.

I'm sure there are other ideas, those are just the first two I had.

Thanks for the quick reply. I am using code behind for both click events.
Is there away I can find out which textbox the return key was pressed on in
code behind?
 
C

Curt_C [MVP]

the Request.Form will get you this I believe. Do a IF check for button1, if
it's there it was clicked, if it wasn't then check for Button2.

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
 
G

Greg

Curt_C said:
the Request.Form will get you this I believe. Do a IF check for button1, if
it's there it was clicked, if it wasn't then check for Button2.

Unfortunately, when the user hits the enter on Textbox2 Button1 click event
is called. Nothing in the Request.Form about Button2. I did notice that
when I click on Textbox1 focus is set on Button1, but if I click on Textbox2
focus is not set on Button2. So, the default button is apparently Button1,
but that's a problem if I can't specify which textbox goes with which
button.

I found some client-side code to set the return event for the Textbox's but
it was VBScript so it didn't work with Mozilla browser and I also needed to
change the Textbox from a webform control to an html control, which I'd
prefer not to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top