how we set this defaultbutton property to textbox, because there is no such propety in the textbox control. and one more thing i am using asp.net 2.0 login view control. can you please suggest me in this.
For those who are using the .Net 2.0 login control, I just thought about a hacky way to implement the scenario where users can hit the Enter key to fire the login button event, here is how it works:
1- wrap your login control into a Panel and call it Panel1.
2- inset a button on stage and call it dummyButton, set it's width and height to 0, set it border to none and it is background anad foreground to white set it is text to empty string.( this is way, dummybutton will be invisible). If you are wondering why
wouldn't I just set the visibility to false, well the answer is that it won't work.
3- set the defaultbutton of Panel1 to dummyButton and set put this code the dummyButton your click handler
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
After much seraching, I found a workable solution to this problem. Basically we need to manually set up the same client code that would be injected if we were using a Default button for a panel.
Assume we have a <asp:Login ... /> control on a page named "Login1"
In the Page_Load event handler:
------
Control ctl = Login1.FindControl("LoginButton");
if(ctl != null && ctl
is IButtonControl)
Login1.Attributes.Add("onkeypress",
string.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')",ctl.ClientID));
-------
I'm assuming that we also have the WebForm_FireDefaultButton client script file available on the page... (if not - you'll get a JavaScript error)
Not sure why you guys are still having problems after this post. I'm using .Net 2.0 Login controls and this worked great for me. I'm using VB thought I coudln't translate the If Then check to see if it's a button and null, but the rest of it worked great.
What's the reason for all this Panel1 and invisible buttons for?
My Code Behind, just like the post:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ctl As Control = userLogin.FindControl("LoginButton")
userLogin.Attributes.Add("onkeypress", String.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')", ctl.ClientID))
End Sub
rmr.adduri
Member
248 Points
62 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 25, 2006 05:40 AM|LINK
Ram Mohan Rao Adduri,
Techinical Associate,
Prokarma
Hyderabad.
Mobile: 9490118545
manish k
Member
14 Points
5 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 25, 2006 07:17 PM|LINK
hi,
the above code given, is much complecated one.
bachbouch
Member
482 Points
86 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 08, 2006 02:44 AM|LINK
For those who are using the .Net 2.0 login control, I just thought about a hacky way to implement the scenario where users can hit the Enter key to fire the login button event, here is how it works:
1- wrap your login control into a Panel and call it Panel1.
2- inset a button on stage and call it dummyButton, set it's width and height to 0, set it border to none and it is background anad foreground to white set it is text to empty string.( this is way, dummybutton will be invisible). If you are wondering why wouldn't I just set the visibility to false, well the answer is that it won't work.
3- set the defaultbutton of Panel1 to dummyButton and set put this code the dummyButton your click handler
bool crediteUser = Membership.ValidateUser(Login1.UserName, Login1.Password);
if (crediteUser)
{
FormsAuthentication.RedirectFromLoginPage(Login1.UserName,false);
}
Hope this helps
-----
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
medo75
Member
10 Points
10 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 10, 2006 01:25 AM|LINK
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 10, 2006 05:30 AM|LINK
captobvious
Member
69 Points
20 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 10, 2006 05:31 AM|LINK
rmr.adduri
Member
248 Points
62 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 10, 2006 07:19 AM|LINK
Ram Mohan Rao Adduri,
Techinical Associate,
Prokarma
Hyderabad.
Mobile: 9490118545
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 10, 2006 12:10 PM|LINK
FMastro
Member
624 Points
160 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 11, 2006 12:14 PM|LINK
After much seraching, I found a workable solution to this problem. Basically we need to manually set up the same client code that would be injected if we were using a Default button for a panel.
Assume we have a <asp:Login ... /> control on a page named "Login1"
In the Page_Load event handler:
------
Control ctl = Login1.FindControl("LoginButton");
if(ctl != null && ctl is IButtonControl)
Login1.Attributes.Add("onkeypress", string.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')",ctl.ClientID));
-------
I'm assuming that we also have the WebForm_FireDefaultButton client script file available on the page... (if not - you'll get a JavaScript error)
Not sure why you guys are still having problems after this post. I'm using .Net 2.0 Login controls and this worked great for me. I'm using VB thought I coudln't translate the If Then check to see if it's a button and null, but the rest of it worked great. What's the reason for all this Panel1 and invisible buttons for?
My Code Behind, just like the post:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ctl As Control = userLogin.FindControl("LoginButton")
userLogin.Attributes.Add("onkeypress", String.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')", ctl.ClientID))
End Sub
My ASPX Page:
<asp:Login ID="userLogin" runat="server" LoginButtonImageUrl="~/images/buttons/log_in.gif"
LoginButtonType="Image" PasswordRecoveryText="Forgot Password?" PasswordRecoveryUrl="/ForgotPassword.aspx"
TitleText="User Login" UserNameLabelText="User ID:" >
<TitleTextStyle Font-Bold="True" Font-Size="Medium" ForeColor="SteelBlue" />
<TextBoxStyle Width="135px" />
<LabelStyle Font-Bold="True" />
</asp:Login>
FredMastro.Com
sdgscott
Member
15 Points
6 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Oct 30, 2006 08:36 PM|LINK
Thanks FMastro,
I added a generic help button to my master page and the enter key started firing the help button instead of the login
button. Your solution is just what I needed!