Behaviors when "Enter" is pressed

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Behaviors when "Enter" is pressed

Post by heinscott » Thu Sep 04, 2008 3:09 pm

On my basket page (amongst others), I've noticed that no matter where the cursor is focused, the default behavior of an Enter press is to run the Search control. I know that customers will be confused when they are trying to either enter a coupon code or estimate their shipping, and instead get a search results page.
Any ideas on this? If this helps, I've noticed that the shipping estimator works with an Enter press, but only in Internet Explorer (not firefox). The coupon code box does not work on either browser with an enter press.

Thanks for the help!

Scott

bluecherry
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 26
Joined: Sat May 24, 2008 3:45 pm

Re: Behaviors when "Enter" is pressed

Post by bluecherry » Thu Sep 04, 2008 3:31 pm

heinscott wrote:On my basket page (amongst others), I've noticed that no matter where the cursor is focused, the default behavior of an Enter press is to run the Search control. I know that customers will be confused when they are trying to either enter a coupon code or estimate their shipping, and instead get a search results page.
Any ideas on this? If this helps, I've noticed that the shipping estimator works with an Enter press, but only in Internet Explorer (not firefox). The coupon code box does not work on either browser with an enter press.

Thanks for the help!

Scott
I also notice this in Firefox under Administration > Catalog -> Search This Category

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Behaviors when "Enter" is pressed

Post by jmestep » Thu Sep 04, 2008 3:44 pm

There is some code in the PageHelper.cs that you might be able to adapt/use. I just haven't researched it.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Behaviors when "Enter" is pressed

Post by mazhar » Thu Sep 04, 2008 10:02 pm

you could try something like the following

Code: Select all

PageHelper.SetDefaultButton(KeepShoppingButton, KeepShoppingButton.ClientID);
        KeepShoppingButton.Focus();

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: Behaviors when "Enter" is pressed

Post by heinscott » Fri Sep 05, 2008 8:30 am

Where exactly would I use that code? I tried pasting, for instance:

PageHelper.SetDefaultButton(ApplyCouponButton, ApplyCouponButton.ClientID);

into the Page_Load section of my Conlib/CouponDialog.ascx.cs.

Didn't do anything differently for me.

Thanks,

Scott

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: Behaviors when "Enter" is pressed

Post by heinscott » Fri Sep 05, 2008 8:47 am

I figured out that if you wrap all the page elements in an <asp:panel> and apply a default button for the panel, that pressing Enter will produce the desired results. But only in Internet Explorer. Firefox still pulls the search (or, first button on the page). Any more ideas for me?
Thanks,

Scott

...BTW, it seems that ClientId is not a valid property of a LinkButton. If I change to an Asp:Button, behavior works correctly (in firefox), but looks terrible. Any idea of how to get the ClientId of a LinkButton so that Setting the default button will work??

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: Behaviors when "Enter" is pressed

Post by heinscott » Fri Sep 05, 2008 10:38 am

Okay. I finally figured out a solution that seems to work, at least for now (unless someone gives me an easier one).
First, make sure that all input elements and buttons that need a default button behavior associated with them are wrapped in an asp:Panel, setting the DefaultButton="HiddenButtonInQuestion"...
The HiddenButtonInQuestion should be a regular <asp:Button>, where its OnClick fires the same event as the <asp:LinkButton>. Since an asp:Button will not fire when it contains: Visible="false", instead include the line:
style="visibility:hidden". So, essentially you will have something like:

Code: Select all

<asp:Panel ID="CouponPanel" runat="server" DefaultButton="HiddenCouponButton">
<div class="section">
    <div class="header">
        <h2><asp:Localize ID="Caption" runat="server" Text="Coupon or Promotional Code" EnableViewState="false"></asp:Localize></h2>
    </div>
    <div class="onePageCheckoutCell2">
        <asp:Label ID="InvalidCouponMessage" runat="server" Text="Invalid coupon code.<br /><br />" Visible="false" SkinID="ErrorCondition" EnableViewState="false"></asp:Label>
        <asp:Label ID="NotCombineCouponRemoveMessage" runat="server" Text="The coupon {0} can not be combined with other coupons. Coupons {1} have been removed.<br /><br />" Visible="false" SkinID="ErrorCondition" EnableViewState="false"></asp:Label>
        <asp:Label ID="CombineCouponRemoveMessage" runat="server" Text="The coupon {0} can not be combined with coupon {1}. Coupon {2} has been removed.<br /><br />" Visible="false" SkinID="ErrorCondition" EnableViewState="false"></asp:Label>
        <asp:Label ID="ValidCouponMessage" runat="server" Text="Coupon accepted.<br /><br />" Visible="false" SkinID="GoodCondition" EnableViewState="false"></asp:Label>
        <asp:TextBox ID="CouponCode" runat="server" Width="110px" MaxLength="100" EnableViewState="false"></asp:TextBox>
        <asp:LinkButton ID="ApplyCouponButton" runat="server" Text="Apply" OnClick="ApplyCouponButton_Click" CausesValidation="false" EnableViewState="false" SkinID="Button" />
        <asp:Button ID="HiddenCouponButton" runat="server" style="visibility:hidden" OnClick="ApplyCouponButton_Click" CausesValidation="false" EnableViewState="false" />
    </div>
</div>
</asp:Panel>
This does seems like a lot of work to go through for such a small thing, so, if anyone has a better solution, I would love to implement it!

Thanks for the help.

Scott

herchenx
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Mon Sep 24, 2007 4:10 pm
Location: Fort Collins, CO

Re: Behaviors when "Enter" is pressed

Post by herchenx » Tue Sep 09, 2008 1:07 pm

I was having a similar - *very annoying* - problem in the admin tool. When I am editing the textareas for a product, if I hit "enter" - instead of inserting a carriage return, the page was submitting.

I looked at the code behind and commented out one line of code and it works as I would expect it to.

in /Admin/Products/EditProduct.aspx.cs

Line # 34
// Page.Form.DefaultButton = SaveButton.UniqueID;

I don't know how many other pages have default buttons set in this way, but it could help resolve some similar issues.

jonw2m
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 35
Joined: Thu Sep 15, 2011 9:00 pm

Re: Behaviors when "Enter" is pressed

Post by jonw2m » Thu Feb 14, 2013 10:43 pm

I did a custom page and I tried PageHelper.SetPageDefaultButton, - that worked on IE and Chrome, but not Firefox.
Then I used PageHelper.PreventFirefoxSubmitOnKeyPress which didn't work. Only when I made a hidden button with the same Onclick value and assigned it as default button it worked - just as heinscott suggested almost five years ago.
Thank you,

Post Reply