Setting enter key default button when login control and search button on same page!!!

Last post 07-20-2009 1:34 PM by Jenner_30. 7 replies.

Sort Posts:

  • Setting enter key default button when login control and search button on same page!!!

    06-24-2005, 9:18 PM
    • Member
      449 point Member
    • jtoth55
    • Member since 03-22-2005, 12:17 AM
    • Maryland
    • Posts 158
    I have a login control... The default behavior is that if a user enters in their user name and password and then hit enter (rather than clicking the button), it doesn't trigger the login button but triggers my search button on the top of the page instead.

    How can I remedy this problem?
    Justin Toth
    http://tothsolutions.com
    http://tothsolutions.com/blog
  • Re: Setting enter key default button when login control and search button on same page!!!

    06-28-2005, 1:25 PM
    Hi Justin,

    You could add a Panel control and set the DefaultButton property to the control you wish to receive a click when enter is pressed in one of the Panel's controls.  (In addition to Panels, the Form itself also supports a DefaultButton property.)  This way, you should be able to "bucket" the controls to cause the correct button to click on enter in each case.

    A related article - http://weblogs.asp.net/skoganti/archive/2004/09/20/231695.aspx

    Here's a simple Panel-based example (from: http://www.developer.com/net/asp/article.php/10917_3506896_3):
    <html>
    <body>
    <form id="Form2" runat="server">
    <asp:Panel ID="Panel1" DefaultButton="Button1" RunAt="server">
    <asp:Button ID="Button1" RunAt="server"/>
    </asp:Panel>
    <asp:Panel ID="Panel2" DefaultButton="Button2" RunAt="server">
    <asp:Button ID="Button2" RunAt="server"/>
    </asp:Panel>
    </form>
    </body>
    </html>

    Hope this helps!
    -Chris

  • Re: Setting enter key default button when login control and search button on same page!!!

    06-28-2005, 8:12 PM
    • Member
      449 point Member
    • jtoth55
    • Member since 03-22-2005, 12:17 AM
    • Maryland
    • Posts 158
    Unfortunately, I do not just have button1 and button2. Like I said, I have a Login control, so I am not actually using a button (it is generated when the login control is converted to html.)
    Justin Toth
    http://tothsolutions.com
    http://tothsolutions.com/blog
  • Re: Setting enter key default button when login control and search button on same page!!!

    07-04-2005, 5:20 PM
    • Member
      449 point Member
    • jtoth55
    • Member since 03-22-2005, 12:17 AM
    • Maryland
    • Posts 158
    Does anyone else have any ideas about this?
    Justin Toth
    http://tothsolutions.com
    http://tothsolutions.com/blog
  • Re: Setting enter key default button when login control and search button on same page!!!

    07-06-2005, 1:14 PM
    • Participant
      1,108 point Participant
    • farmas
    • Member since 08-05-2002, 12:19 PM
    • Redmond, WA
    • Posts 246
    • AspNetTeam
    You could use the Panel solution proposed above by giving the UniqueId of the Login control submit button. For example, if the ID of the Login control is "Login1" then the panel would look like this:

    <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px" DefaultButton="Login1$LoginButton">
                <asp:Login ID="Login1" runat="server">
                </asp:Login>
            </asp:Panel>

    If this doesn't suit your needs, you could set the default button by means of JavaScript. Take a look at post http://forums.asp.net/507628/ShowPost.aspx for sample code on how to do this.

    Hope it helps,
    - Federico
  • Re: Setting enter key default button when login control and search button on same page!!!

    10-27-2005, 9:28 AM
    • Member
      20 point Member
    • fischer
    • Member since 10-27-2005, 1:22 PM
    • Guthenburg, Sweden
    • Posts 4
    This works pretty good. Although I have one scenario when this doesn't work.

    I write wrong imput to the login and the validation control tells me I did wrong. I then type the right (or wrong) info and press enter again. This time the defaultbutton somehow was lost and the serchbutton (in my case an imagebutton) in master page is pressed instead.

    I have tryed many scenarios to find the error.. thought maybe had anything to do with client validation or something...
  • Re: Setting enter key default button when login control and search button on same page!!!

    04-28-2006, 8:04 AM
    • Contributor
      2,898 point Contributor
    • jminond
    • Member since 07-21-2003, 6:33 PM
    • New York
    • Posts 608

    I found that in my runtime for somereason the loginbutton has that full text... so i needed to do

    SetDefaultButton(l.ClientID + "_LoginButton");

    Also, i modified the js to use getElementById as most people dont use name attributes anymore.

    Jonathan Minond
    http://www.Jonavi.com
    http://www.jonavi.com/Default.aspx?pageID=21
    http://RainbowBeta.com
    http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
    http://dotnetslackers.com/community/blogs/jminond/default.aspx
  • Re: Setting enter key default button when login control and search button on same page!!!

    07-20-2009, 1:34 PM
    • Member
      6 point Member
    • Jenner_30
    • Member since 04-17-2009, 3:43 PM
    • Posts 15

    I've tried this (and a few other solutions found on the forums) but nothing seems to work for me. I have a loginview with a login control in the Anonymous Template, and have tried this Panel default button solution but my page's default button remains my search button at the top. My code is identical to yours, except it's wrapped in the template:

    <AnonymousTemplate>
    <asp:Panel ID="Panel1" runat="server" DefaultButton="Login1$LoginButton">
    <asp:Login ID="Login1" runat="server" />
    </asp:Panel>
    </AnonymousTemplate>

    I've also tried the Javascript method you linked to, but it doesn't work for me either.
    Does anyone have a good solution to this?

Page 1 of 1 (8 items)