the mystery of a default button

Discussion in 'ASP .Net' started by Guest, Dec 25, 2005.

  1. Guest

    Guest Guest

    This is quite serious - for a beginner...
    No property setting for a default button? I just want a button on a search
    page to automatically be pressed when I hit the return/enter key.

    Somehow I did it with one of my 2 buttons, (but I don't know how)
    one of the buttons (cmdClear) decided on its own to be the default button -
    instead of the cmdSearchMember button - so much so that even after searching
    and finding 2 other solutions:
    1) 'RegisterHiddenField("__EVENTTARGET", "cmdSearchMember")
    2) Javascript -that ends up with:
    SetDefaultButton(Me.txtNAME_ID, cmdSearchMember) in the load event of
    the form.

    .... the other button (cmdClear) continues to be selected and is
    automatically pushed when I hit the enter (return) key.

    Please help, I know the solution isn't to grab my code from the
    cmdSearchMember button and add it to the cmdClear button - although that is
    becoming quite tempting.
    Guest, Dec 25, 2005
    1. Advertisements

  2. If you are in 2.0, you do have property DefaultButton.

    In 1.1 the first button on the form is always the default one.

    Eliyahu Goldin, Dec 25, 2005
    1. Advertisements

  3. Guest

    Guest Guest

    Hi Jonefer,

    You do not have to switch the code in your buttons. In ASP.NET 1.1, you may
    still create a webpage with more than one section in it; each section can
    have the equivalent of a "default" by adding a few lines of JavaScript to
    attach the event OnKeyPress of each textbox to trigger a different button's
    Click event. For a demo take a look at this sample:
    Guest, Dec 25, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.