I have a page with two forms, one with just one textbox, and the other with many textboxes, dropdownlists, checkboxes, etc. This is a search page, with the results showing up in popups. The basic requirement is that if the user types in a value in the first
textbox and hits the ENTER key, the first form is submitted and a popup shows the results of the search. If the user fills in any fields in the second part of the form and hits ENTER on any textbox, the second form is submitted and the results are popped
up. The two popups are different, obviously.
I've been struggling with how to capture the ENTER key and send the user one or the other result popup. Then someone directed me to your article here. I inserted two panels enclosing the two different sets of controls into the panels. I set the defaultbutton
for the panels and tried it out. It works the first time I hit the ENTER key on any field. But if the user hits ENTER again, the first form is ALWAYS submitted. So, for example, if they didn't get the restuls they expected and went back to the main form
and added more criteria and hit ENTER, it would submit the first form, which is incorrect. The user has to refresh the page to get the second form to submit on ENTER (or click the submit button). This won't work for us. I'm wondering if this is a bug, and
if so is there a workaround? if not, what could I be missing to cause this behavior?
Thanks so much for your help - this webapp is nearly done, but this issue is causing me a lot of headaches! Hopefully this will be resolved soon.
Thanks again,
eddie
I'm having the same problem with two
controls on the same page (Signin & Signup)
I wonder if this was forgotten when creating ASP.NET coz I can not thing on any "EZ workaround" (as it was so EZ 2 implement on classic ASP)
So now - whenever the control area is being clicked (or focused) or any control inside it - the default button will used,
It will not go to a default button if the focus is outside of these two controls (for example - on the web site header) - the following script might also B useful:
<script language="javascript">
// <!--
function onKeySignin()
{
if (window.event.keyCode == 13)
{
document.getElementById('<%=_buttonSignin.ClientID%>').focus();
document.getElementById('<%=_buttonSignin.ClientID%>').click();
}
}
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)
People go through periods in the lives - I'd rather go through exclamation points.
- Schultz
Hi, In my site also this is the problem. in my site i am using master pages and in the master page i have a usercontrol in the usercontrol i have an image button. and when i go to login page in that login page i used a login control. when i open login page
and enter the user name and password and hit enter then the search button gets fired. so i searched for this in the forms but i didint find any information regarding this. so can you please help me regarding this.
Folks, you have to remember that not everyone is using old login controls. We are using the new .NET 2.0 Membership API. Thus .NET provides the button and textboxes. Plus, if you're using master pages, you can't simply play around with defaultbutton because
what button are you referring to if you are using a master page? that is not possible as differrent detail pages will have it's own button!
This is something you should be able to do. I had a boss who insisted on it, rather than just disabling the enter key. It should be textbox driven though, its not a good idea to use Panels just for this purpose, unless you use them anyway for other reasons.
So this can be used at the FORM level and PANEL level. Where else? Textbox (or other control) would be ideal.
<asp:TextBox defaultbutton="soandso">
You may have a reason to point one textbox to one button and another textbox to another button.
fengkui
Member
5 Points
1 Post
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Aug 23, 2006 05:03 PM|LINK
Yovav
Member
702 Points
181 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Aug 24, 2006 01:09 AM|LINK
I'm having the same problem with two controls on the same page (Signin & Signup)
I wonder if this was forgotten when creating ASP.NET coz I can not thing on any "EZ workaround" (as it was so EZ 2 implement on classic ASP)
any ideas ?
code samples ?
(hate to mess with all those low level events :-)
Best Regards
YovavG@GMail.com
LudovicoVan
Star
9692 Points
1935 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Aug 24, 2006 10:47 AM|LINK
Yovav:> I'm having the same problem with two controls on the same page
Just an idea, not checked:
DefaultButton='<%= MyControl.FindControl("MyControlButton").ClientID %>'
Let me know.
-LV
Yovav
Member
702 Points
181 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Aug 24, 2006 04:49 PM|LINK
Another sample code (to be applied on each control):
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Signin.ascx.cs" Inherits="Signin" %>
<
asp:Panel DefaultButton="_buttonSignin" runat="server">...
</
asp:Panel><%@ Control Language="C#" AutoEventWireup="true" CodeFile="Signup.ascx.cs" Inherits="Signup" %>
<
asp:Panel DefaultButton="_buttonSignup" runat="server">...
</
asp:Panel>So now - whenever the control area is being clicked (or focused) or any control inside it - the default button will used,
It will not go to a default button if the focus is outside of these two controls (for example - on the web site header) - the following script might also B useful:
<script language="javascript">
// <!--
function onKeySignin()
{
if (window.event.keyCode == 13)
{
document.getElementById('<%=_buttonSignin.ClientID%>').focus();
document.getElementById('<%=_buttonSignin.ClientID%>').click();
}
}
document.attachEvent("onkeydown", onKeySignin);
// -->
</script>
Best Regards
YovavG@GMail.com
GrantDG
Member
15 Points
3 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Aug 28, 2006 05:09 AM|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)
- Schultz
rmr.adduri
Member
248 Points
62 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 01, 2006 04:31 PM|LINK
Hi, In my site also this is the problem. in my site i am using master pages and in the master page i have a usercontrol in the usercontrol i have an image button. and when i go to login page in that login page i used a login control. when i open login page and enter the user name and password and hit enter then the search button gets fired. so i searched for this in the forms but i didint find any information regarding this. so can you please help me regarding this.
Ram Mohan Rao Adduri,
Techinical Associate,
Prokarma
Hyderabad.
Mobile: 9490118545
dba123
Contributor
2726 Points
1364 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 19, 2006 09:20 PM|LINK
Folks, you have to remember that not everyone is using old login controls. We are using the new .NET 2.0 Membership API. Thus .NET provides the button and textboxes. Plus, if you're using master pages, you can't simply play around with defaultbutton because what button are you referring to if you are using a master page? that is not possible as differrent detail pages will have it's own button!
This is stupid, there must be an easy workaround.
rmr.adduri
Member
248 Points
62 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 20, 2006 06:00 AM|LINK
Hi GrantDG,
Can you provide the WebForm_FireDefaultButton client script.
Ram Mohan Rao Adduri,
Techinical Associate,
Prokarma
Hyderabad.
Mobile: 9490118545
rmr.adduri
Member
248 Points
62 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 20, 2006 06:02 AM|LINK
Hi dba123,
If u find any solution for this, can u please suggest me to solve this problem.
Ram Mohan Rao Adduri,
Techinical Associate,
Prokarma
Hyderabad.
Mobile: 9490118545
netmongamma
Member
26 Points
13 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 20, 2006 04:05 PM|LINK
This is something you should be able to do. I had a boss who insisted on it, rather than just disabling the enter key. It should be textbox driven though, its not a good idea to use Panels just for this purpose, unless you use them anyway for other reasons. So this can be used at the FORM level and PANEL level. Where else? Textbox (or other control) would be ideal.
<asp:TextBox defaultbutton="soandso">
You may have a reason to point one textbox to one button and another textbox to another button.