Two text boxes each with their own button

Discussion in 'ASP .Net' started by Greg, Feb 4, 2004.

  1. Greg

    Greg Guest

    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?
     
    Greg, Feb 4, 2004
    #1
    1. Advertising

  2. Greg

    Curt_C [MVP] Guest

    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.

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


    "Greg" <> wrote in message
    news:...
    > 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?
    >
    >
     
    Curt_C [MVP], Feb 4, 2004
    #2
    1. Advertising

  3. Greg

    Greg Guest

    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:...
    > 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.
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >


    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?
     
    Greg, Feb 4, 2004
    #3
  4. Greg

    Curt_C [MVP] Guest

    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


    "Greg" <> wrote in message
    news:...
    > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    > news:...
    > > 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.
    > >
    > > --
    > > Curt Christianson
    > > Owner/Lead Developer, DF-Software
    > > www.Darkfalz.com
    > >

    >
    > 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?
    >
    >
     
    Curt_C [MVP], Feb 4, 2004
    #4
  5. Greg

    Greg Guest

    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:...
    > 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


    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.
     
    Greg, Feb 4, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Cheng[MSFT]
    Replies:
    0
    Views:
    867
    Steven Cheng[MSFT]
    Sep 22, 2005
  2. John D.
    Replies:
    13
    Views:
    6,985
    david m wicker
    May 19, 2004
  3. Fernie
    Replies:
    9
    Views:
    994
    David Dorward
    Dec 5, 2004
  4. Stefan Mueller
    Replies:
    5
    Views:
    12,401
    jamesxa
    Jun 16, 2009
  5. gmduncan
    Replies:
    1
    Views:
    324
    Peter Hansen
    Jul 7, 2003
Loading...

Share This Page