Forums

OnKeyPress Form Submits/Does Postback

Last post 8/27/2008 11:04 AM by Dan. 4 replies.
Sort Posts: Previous Next
  • Dan

    OnKeyPress Form Submits/Does Postback

    8/25/2008 2:04 PM
    • Top 500 Contributor
    • Joined on 3/24/2008
    • Posts 59

    Hello -

    I'm having an issue where I'm trying to capture the "enter" keypress event and triggering the callback panel event for a button. Basically, the form always performs a postback even though I've captured the Enter key event. If I click the aspxButton the form behaves as expected. It validates the fields and displays appropriate messages. When the Enter Key is pressed, it validates the fields then appears to do a postback clearing out the messages. Thanks.

    ////aspxRoundPanel:////

                        <dxrp:ASPxRoundPanel ID="pnlLogin" runat="server" Width="450px" Height="200px" DefaultButton="btnLogin" ShowHeader="False" HorizontalAlign="Center" ClientInstanceName="clLogin" EnableClientSideAPI="True">

    ////aspxButton/////

                        <dxe:ASPxButton ID="btnLogin" UseSubmitBehavior="false" CausesValidation="true" runat="server" Text="Log In" ClientInstanceName="btnLogin" EnableClientSideAPI="True" AutoPostBack="False" Height="26px" Width="76px" CssFilePath="~/App_Themes/Glass/{0}/styles.css" CssPostfix="Glass" Cursor="pointer">
                            <ClientSideEvents Click="function(s, e) {
                             if(ASPxClientEdit.ValidateGroup('entryGroup')) {
                                CallbackPanel.PerformCallback(e);
                                }
                            }" />
                            <Image AlternateText="Log In" />
                            <Border BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px" />
                        </dxe:ASPxButton>

    ////Here is my BLOCKED SCRIPT/////

    function checkEnter(e){ //e is event object passed from function invocation
                var characterCode //literal character code will be stored in this variable

                if(e && e.which){ //if which property of event object is supported (NN4)
                e = e
                characterCode = e.which //character code is contained in NN4's which property
                }
                else{
                e = event
                characterCode = e.keyCode //character code is contained in IE's keyCode property
                }

                if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
                alert("test");
                return false;
                }
                else{
                return false;
                }

                }

  • Alexey M (DevExpress)

    Re: OnKeyPress Form Submits/Does Postback

    8/26/2008 7:10 AM
    • Top 50 Contributor
    • Joined on 11/19/2007
    • Posts 506

    Hi Dan,

    From your code it is not clear where the checkEnter function is called from.

    Generally, this may occur when there is a single editor (textbox, or a plain INPUT element) on the page. And this is a standard behavior of HTML forms.

    Thanks, Alexey M
    R&D, .NET Team
    Developer Express Inc.

    PS. If you wish to receive direct assistance from our Support Team, use Support Center at http://www.devexpress.com/Support/Center
  • Dan

    Re: OnKeyPress Form Submits/Does Postback

    8/26/2008 10:49 AM
    • Top 500 Contributor
    • Joined on 3/24/2008
    • Posts 59

    CheckEnter is in the body tag.

    <body onkeypress="checkEnter(event)">

    I'm guessing this should be able to execute the callback function instead of actually doing a postback on the page?

     

     

  • Alexey M (DevExpress)

    Re: OnKeyPress Form Submits/Does Postback

    8/27/2008 2:28 AM
    • Top 50 Contributor
    • Joined on 11/19/2007
    • Posts 506
    Answer

    Try this:

    <body onkeypress="return checkEnter(event)">

    Thanks, Alexey M
    R&D, .NET Team
    Developer Express Inc.

    PS. If you wish to receive direct assistance from our Support Team, use Support Center at http://www.devexpress.com/Support/Center
  • Dan

    Re: OnKeyPress Form Submits/Does Postback

    8/27/2008 11:04 AM
    • Top 500 Contributor
    • Joined on 3/24/2008
    • Posts 59

    Oops. That worked. Thanks

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.