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.
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.
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.)
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:
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.
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...
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:
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?
jtoth55
Member
465 Points
184 Posts
Setting enter key default button when login control and search button on same page!!!
Jun 25, 2005 01:18 AM|LINK
How can I remedy this problem?
http://tothsolutions.com
http://www.sportsalert.com
Christopher...
Member
75 Points
15 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Jun 28, 2005 05:25 PM|LINK
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):
Hope this helps!
-Chris
Senior Architect, Monster.com
http://dotnetjunkies.com/WebLog/christopherbowen/
jtoth55
Member
465 Points
184 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Jun 29, 2005 12:12 AM|LINK
http://tothsolutions.com
http://www.sportsalert.com
jtoth55
Member
465 Points
184 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Jul 04, 2005 09:20 PM|LINK
http://tothsolutions.com
http://www.sportsalert.com
farmas
Participant
1164 Points
259 Posts
AspNetTeam
Re: Setting enter key default button when login control and search button on same page!!!
Jul 06, 2005 05:14 PM|LINK
<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
fischer
Member
20 Points
4 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Oct 27, 2005 01:28 PM|LINK
jminond
Contributor
2898 Points
608 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Apr 28, 2006 12:04 PM|LINK
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.
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
Jenner_30
Member
6 Points
15 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Jul 20, 2009 05:34 PM|LINK
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:
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?
Escarcha
Member
8 Points
5 Posts
Re: Setting enter key default button when login control and search button on same page!!!
Jan 14, 2010 06:52 PM|LINK
Hello I had this problem...the panel solution works but you have to convert the login control to template .
In order to do this:
And thats it very easy :) !!!
Hope this help
Juan
This is my login control after this steps
<div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Login ID="lngMainLogin" runat="server" CssClass="alignleft"</div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> DestinationPageUrl="~/AdminTool/BarriosUrb/Default.aspx" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> FailureText="No hemos podido validar su información. Verifique su username o su password." </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> PasswordRecoveryUrl="~/UserHelp/ForgotPass.aspx" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> PasswordRequiredErrorMessage="Password es requiredo." </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> UserNameRequiredErrorMessage="User Name es requiredo." </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> onloggedin="lngMainLogin_LoggedIn" onloggingin="lngMainLogin_LoggingIn" ></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <LayoutTemplate></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Panel runat="server" ID="pnlLogin" DefaultButton="LoginButton"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <table border="0" cellpadding="0" cellspacing="5" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> style="border-collapse:collapse;"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <div id="loginC"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <table ></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td align="center" colspan="2"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <h4>Accede Puerto Rico e</h4></td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td align="right"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TextBox ID="UserName" runat="server"></asp:TextBox></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ControlToValidate="UserName" ErrorMessage="User Name is required." </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ToolTip="User Name is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td align="right"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ControlToValidate="Password" ErrorMessage="Password is required." </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ToolTip="Password is required." ValidationGroup="ctl00$lngMainLogin">*</asp:RequiredFieldValidator></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CheckBox CssClass="checknoborder" ID="RememberMe" runat="server" Text="Remember me" /></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <a href="ForgotPass.aspx" title="Olvidaste tu contraseña" >¿Olvidaste tu contraseña?</a> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td align="center" colspan="2" style="color:Red;"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <td align="right" colspan="2"></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Button ID="LoginButton" CssClass="button" runat="server" CommandName="Login" Text="Log In" </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> ValidationGroup="ctl00$lngMainLogin" /></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </table></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> </div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </td></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </tr></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </table></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:Panel></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </LayoutTemplate></div> <div style="position: absolute; left: -10000px; top: 135px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:Login> </div><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>
</td>
<td>
<a href="ForgotPass.aspx" title="Olvidaste tu contraseñ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>
naeem_m2
Member
2 Points
1 Post
Re: Setting enter key default button when login control and search button on same page!!!
Feb 27, 2010 07:24 AM|LINK
thanks it works