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

Last post 01-14-2010 2:52 PM by Escarcha. 8 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 160
    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 160
    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 160
    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,138 point Participant
    • farmas
    • Member since 08-05-2002, 12:19 PM
    • Redmond, WA
    • Posts 251
    • 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, 7: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?

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

    01-14-2010, 2:52 PM
    • Member
      2 point Member
    • Escarcha
    • Member since 01-14-2010, 2:41 PM
    • Posts 1

    Hello I had this problem...the panel solution works but you have to convert the login control to template .

    In order to do this:

    1. switch to design view
    2. Click the arrow in the right upper corner.
    3. Click convert to template 
    4. Your going to see the layout in html of the login control
    5. Search for the <LayoutTemplate> tag
    6. Put your panel in
    7. Close your panel before the layout close <LayoutTemplate/>
    8. set the panel defaultbutton property with the name of the login button in most cases LoginButton

    And thats it very easy :) !!!

    Hope this help
    Juan 


    This is my login control after this steps


        <asp:Login ID="lngMainLogin" runat="server"  CssClass="alignleft"
            DestinationPageUrl="~/AdminTool/BarriosUrb/Default.aspx" 
            FailureText="No hemos podido validar su información.  Verifique su username o su password." 
            PasswordRecoveryUrl="~/UserHelp/ForgotPass.aspx" 
            PasswordRequiredErrorMessage="Password es requiredo." 
            UserNameRequiredErrorMessage="User Name es requiredo." 
            onloggedin="lngMainLogin_LoggedIn" onloggingin="lngMainLogin_LoggingIn" >
            <LayoutTemplate>
              
              <asp:Panel runat="server" ID="pnlLogin" DefaultButton="LoginButton">
                <table border="0" cellpadding="0" cellspacing="5" 
                    style="border-collapse:collapse;">
                    <tr>
                        <td>
                        <div id="loginC">
                            <table >
                                <tr>
                                    <td align="center" colspan="2">
                                        <h4>Accede Puerto Rico e</h4></td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                            ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                            ToolTip="User Name is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                            ControlToValidate="Password" ErrorMessage="Password is required." 
                                            ToolTip="Password is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:CheckBox  CssClass="checknoborder" ID="RememberMe" runat="server" Text="Remember me" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;</td>
                                    <td>
                                    <a href="ForgotPass.aspx" title="Olvidaste tu contrase&ntilde;a" >¿Olvidaste tu contraseña?</a>   </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" style="color:Red;">
                                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="LoginButton" CssClass="button" runat="server" CommandName="Login" Text="Log In" 
                                            ValidationGroup="ctl00$lngMainLogin" />
                                            
                                    </td>
                                </tr>
                            </table>
                        </div>    
                        </td>
                    </tr>
                </table>
                 </asp:Panel>
            </LayoutTemplate>
        </asp:Login> 

        <asp:Login ID="lngMainLogin" runat="server"  CssClass="alignleft"

            DestinationPageUrl="~/AdminTool/BarriosUrb/Default.aspx" 

            FailureText="No hemos podido validar su información.  Verifique su username o su password." 

            PasswordRecoveryUrl="~/UserHelp/ForgotPass.aspx" 

            PasswordRequiredErrorMessage="Password es requiredo." 

            UserNameRequiredErrorMessage="User Name es requiredo." 

            onloggedin="lngMainLogin_LoggedIn" onloggingin="lngMainLogin_LoggingIn" >

            <LayoutTemplate>

              

              <asp:Panel runat="server" ID="pnlLogin" DefaultButton="LoginButton">

                <table border="0" cellpadding="0" cellspacing="5" 

                    style="border-collapse:collapse;">

                    <tr>

                        <td>

                        <div id="loginC">

                            <table >

                                <tr>

                                    <td align="center" colspan="2">

                                        <h4>Accede Puerto Rico e</h4></td>

                                </tr>

                                <tr>

                                    <td align="right">

                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>

                                    </td>

                                    <td>

                                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>

                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 

                                            ControlToValidate="UserName" ErrorMessage="User Name is required." 

                                            ToolTip="User Name is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator>

                                    </td>

                                </tr>

                                <tr>

                                    <td align="right">

                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

                                    </td>

                                    <td>

                                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 

                                            ControlToValidate="Password" ErrorMessage="Password is required." 

                                            ToolTip="Password is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                    </td>

                                    <td>

                                        <asp:CheckBox  CssClass="checknoborder" ID="RememberMe" runat="server" Text="Remember me" />

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        &nbsp;</td>

                                    <td>

                                    <a href="ForgotPass.aspx" title="Olvidaste tu contrase&ntilde;a" >¿Olvidaste tu contraseña?</a>   </td>

                                </tr>

                                <tr>

                                    <td align="center" colspan="2" style="color:Red;">

                                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>

                                    </td>

                                </tr>

                                <tr>

                                    <td align="right" colspan="2">

                                        <asp:Button ID="LoginButton" CssClass="button" runat="server" CommandName="Login" Text="Log In" 

                                            ValidationGroup="ctl00$lngMainLogin" />

                                            

                                    </td>

                                </tr>

                            </table>

                        </div>    

                        </td>

                    </tr>

                </table>

                 </asp:Panel>

            </LayoutTemplate>

        </asp:Login> 


     




Page 1 of 1 (9 items)