Press enter fire specific button in form in ASP.Net 2

Discussion in 'ASP .Net' started by David Lozzi, Oct 25, 2006.

  1. David Lozzi

    David Lozzi Guest

    Howdy,

    I'm using asp.net 2.0 and am trying to get one text box on the page, after
    the user presses enter, to "click" a specific button. I copied the
    javascript I used for a .net 1.1 web app I did a while ago but it doesn't
    appear to work with .net 2.0? Below is my script. Any ideas?

    <script language="javascript">

    function clickButton(e, buttonid){

    var bt = document.getElementById(buttonid);

    if (typeof bt == 'object'){

    if(navigator.appName.indexOf("Netscape")>(-1)){

    if (e.keyCode == 13){

    bt.click();

    return false;

    }

    }

    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){

    if (event.keyCode == 13){

    bt.click();

    return false;

    }

    }

    }

    }

    </script>



    in the textbox

    onkeydown="javascript: return
    clickButton(event,'_ctl0_uscTopBag_btnSearch');"



    The event fires to the line of bt.click() but it doesn't appear to click it.
    The ID for the button I am sending is what the ID of the button is after the
    page renders, which javascript likes. Any ideas?



    Thanks!!

    David Lozzi
     
    David Lozzi, Oct 25, 2006
    #1
    1. Advertising

  2. in asp.net 2.0, panel's have a defaultButton property which does what you
    want.

    You can see an example at:
    http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

    Karl

    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "David Lozzi" <> wrote in message
    news:%23aJba3%...
    > Howdy,
    >
    > I'm using asp.net 2.0 and am trying to get one text box on the page, after
    > the user presses enter, to "click" a specific button. I copied the
    > javascript I used for a .net 1.1 web app I did a while ago but it doesn't
    > appear to work with .net 2.0? Below is my script. Any ideas?
    >
    > <script language="javascript">
    >
    > function clickButton(e, buttonid){
    >
    > var bt = document.getElementById(buttonid);
    >
    > if (typeof bt == 'object'){
    >
    > if(navigator.appName.indexOf("Netscape")>(-1)){
    >
    > if (e.keyCode == 13){
    >
    > bt.click();
    >
    > return false;
    >
    > }
    >
    > }
    >
    > if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
    >
    > if (event.keyCode == 13){
    >
    > bt.click();
    >
    > return false;
    >
    > }
    >
    > }
    >
    > }
    >
    > }
    >
    > </script>
    >
    >
    >
    > in the textbox
    >
    > onkeydown="javascript: return
    > clickButton(event,'_ctl0_uscTopBag_btnSearch');"
    >
    >
    >
    > The event fires to the line of bt.click() but it doesn't appear to click
    > it. The ID for the button I am sending is what the ID of the button is
    > after the page renders, which javascript likes. Any ideas?
    >
    >
    >
    > Thanks!!
    >
    > David Lozzi
    >
    >
     
    Karl Seguin [MVP], Oct 25, 2006
    #2
    1. Advertising

  3. David Lozzi

    David Lozzi Guest

    But I have only one Form for the page and two or three submit buttons, for
    example

    Top of page is search site textbox with a button
    Middle of page is signup for new account, multiple fields and a submit
    button
    Right of page is a login box with username and password with a submit
    button.

    The signup for new account is fired when enter is pressed in any of the
    sections, which makes sense. How do I specify where to submit to?

    Thanks

    David Lozzi


    "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
    net> wrote in message news:%23O5JCmC%...
    > in asp.net 2.0, panel's have a defaultButton property which does what you
    > want.
    >
    > You can see an example at:
    > http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx
    >
    > Karl
    >
    > --
    > http://www.openmymind.net/
    > http://www.codebetter.com/
    >
    >
    > "David Lozzi" <> wrote in message
    > news:%23aJba3%...
    >> Howdy,
    >>
    >> I'm using asp.net 2.0 and am trying to get one text box on the page,
    >> after the user presses enter, to "click" a specific button. I copied the
    >> javascript I used for a .net 1.1 web app I did a while ago but it doesn't
    >> appear to work with .net 2.0? Below is my script. Any ideas?
    >>
    >> <script language="javascript">
    >>
    >> function clickButton(e, buttonid){
    >>
    >> var bt = document.getElementById(buttonid);
    >>
    >> if (typeof bt == 'object'){
    >>
    >> if(navigator.appName.indexOf("Netscape")>(-1)){
    >>
    >> if (e.keyCode == 13){
    >>
    >> bt.click();
    >>
    >> return false;
    >>
    >> }
    >>
    >> }
    >>
    >> if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
    >>
    >> if (event.keyCode == 13){
    >>
    >> bt.click();
    >>
    >> return false;
    >>
    >> }
    >>
    >> }
    >>
    >> }
    >>
    >> }
    >>
    >> </script>
    >>
    >>
    >>
    >> in the textbox
    >>
    >> onkeydown="javascript: return
    >> clickButton(event,'_ctl0_uscTopBag_btnSearch');"
    >>
    >>
    >>
    >> The event fires to the line of bt.click() but it doesn't appear to click
    >> it. The ID for the button I am sending is what the ID of the button is
    >> after the page renders, which javascript likes. Any ideas?
    >>
    >>
    >>
    >> Thanks!!
    >>
    >> David Lozzi
    >>
    >>

    >
    >
     
    David Lozzi, Oct 25, 2006
    #3
  4. wrap the textboxes in a <asp:panel and specify it's defaultButton.

    I think you are thinking about the defaultButton for the form...but you can
    specify it at the panel level...

    Karl

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    "David Lozzi" <> wrote in message
    news:ui8lopD%...
    > But I have only one Form for the page and two or three submit buttons, for
    > example
    >
    > Top of page is search site textbox with a button
    > Middle of page is signup for new account, multiple fields and a submit
    > button
    > Right of page is a login box with username and password with a submit
    > button.
    >
    > The signup for new account is fired when enter is pressed in any of the
    > sections, which makes sense. How do I specify where to submit to?
    >
    > Thanks
    >
    > David Lozzi
    >
    >
    > "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
    > net> wrote in message news:%23O5JCmC%...
    >> in asp.net 2.0, panel's have a defaultButton property which does what you
    >> want.
    >>
    >> You can see an example at:
    >> http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx
    >>
    >> Karl
    >>
    >> --
    >> http://www.openmymind.net/
    >> http://www.codebetter.com/
    >>
    >>
    >> "David Lozzi" <> wrote in message
    >> news:%23aJba3%...
    >>> Howdy,
    >>>
    >>> I'm using asp.net 2.0 and am trying to get one text box on the page,
    >>> after the user presses enter, to "click" a specific button. I copied the
    >>> javascript I used for a .net 1.1 web app I did a while ago but it
    >>> doesn't appear to work with .net 2.0? Below is my script. Any ideas?
    >>>
    >>> <script language="javascript">
    >>>
    >>> function clickButton(e, buttonid){
    >>>
    >>> var bt = document.getElementById(buttonid);
    >>>
    >>> if (typeof bt == 'object'){
    >>>
    >>> if(navigator.appName.indexOf("Netscape")>(-1)){
    >>>
    >>> if (e.keyCode == 13){
    >>>
    >>> bt.click();
    >>>
    >>> return false;
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
    >>>
    >>> if (event.keyCode == 13){
    >>>
    >>> bt.click();
    >>>
    >>> return false;
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> </script>
    >>>
    >>>
    >>>
    >>> in the textbox
    >>>
    >>> onkeydown="javascript: return
    >>> clickButton(event,'_ctl0_uscTopBag_btnSearch');"
    >>>
    >>>
    >>>
    >>> The event fires to the line of bt.click() but it doesn't appear to click
    >>> it. The ID for the button I am sending is what the ID of the button is
    >>> after the page renders, which javascript likes. Any ideas?
    >>>
    >>>
    >>>
    >>> Thanks!!
    >>>
    >>> David Lozzi
    >>>
    >>>

    >>
    >>

    >
    >
     
    Karl Seguin [MVP], Oct 25, 2006
    #4
    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. Jie
    Replies:
    7
    Views:
    6,156
    Xavier Pacheco
    Oct 9, 2004
  2. gnewsgroup
    Replies:
    0
    Views:
    508
    gnewsgroup
    Dec 27, 2007
  3. Cowboy \(Gregory A. Beamer\)

    Re: when i press enter, logoff button is pressed

    Cowboy \(Gregory A. Beamer\), Jan 27, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    453
    Cowboy \(Gregory A. Beamer\)
    Jan 27, 2009
  4. geronimi
    Replies:
    0
    Views:
    108
    geronimi
    Dec 26, 2005
  5. HopfZ
    Replies:
    0
    Views:
    582
    HopfZ
    Aug 28, 2006
Loading...

Share This Page