Default Button is not working

8 posts, 1 answers
  1. Mona
    Mona avatar
    33 posts
    Member since:
    Jul 2010

    Posted 12 Oct 2010 Link to this post

    Hello All,

    I have a default button which clicks on enter key press. But if the cursor is on the RadCombo box then the enter key is not working. Please help me. I am writing the code for this.

    <asp:Panel ID="Panel1" runat="server" DefaultButton="btnUpdate">
        <div style="position: relative; height: 135px; width: 100%; padding-top: 5px; background-color: #ffe5ad;">
            <asp:ValidationSummary ID="VSReqTrak" ShowSummary="false" HeaderText="Please complete the required fields."
                ShowMessageBox="true" runat="server" />
            <span style="position: absolute; top: 20px; left: 0px; width: 120px; text-align: right;">
                Category: </span>
            <asp:RequiredFieldValidator ErrorMessage="" Text="*" ControlToValidate="rcbCategory"
                Style="position: absolute; top: 21px; left: 123px; height: 20px;" ID="RFVCategory"
                runat="server" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
            <telerik:RadComboBox ID="rcbCategory" runat="server" Width="210px" Style="position: absolute;
                top: 20px; left: 140px;" MarkFirstMatch="true" DataSourceID="ObjCategories" DataTextField="CategoryName"
                AllowCustomText="true" SelectedValue='<%# DataBinder.Eval( Container, "DataItem.CategoryID" ) %>'
                DataValueField="CategoryID">
            </telerik:RadComboBox>
            
                <asp:ImageButton ID="btnUpdate" ToolTip="Update" ImageUrl="~/Images/Update.gif" Text="Update"
                Style="position: absolute; top: 90px; left: 650px;" runat="server" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'
                CommandName="Update" />
            <asp:ImageButton ID="btnCancel" ToolTip="Cancel" ImageUrl="~/Images/Cancel.gif" Text="Cancel"
                Style="position: absolute; top: 90px; left: 680px;" runat="server" CausesValidation="False"
                CommandName="Cancel" />
        </div>
    </asp:Panel>
  2. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 19 Oct 2010 Link to this post

    Hello Mona,

    You can avoid this by putting the following JavaScript code on your page (after the ScriptManager):
    <script type="text/javascript">
        var $p = Telerik.Web.UI.RadComboBox.prototype;
        var keyDownHandler = $p._onKeyDown;
        $p._onKeyDown = function (e) {
            var oReturnValue = e.returnValue;
            var oPreventDefault = e.preventDefault;
            var keyCode = e.keyCode || e.which;
            if (keyCode === 13)
                e.preventDefault = null;
            keyDownHandler.call(this, e);
            if (keyCode === 13) {
                e.returnValue = oReturnValue;
                e.preventDefault = oPreventDefault;
            }
        };
    </script>

    Sincerely yours,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 19 Oct 2010 Link to this post

    Simon,

    Thanks for answering this question for Mona and also myself in another post.

    One caveat to your solution, though, is that you are not checking to see if the dropdown is visible.  Don't you need to utilize the .get_dropDownVisible() method of the RadComboBox so that the default button is not clicked when the dropdown is visible?

    In your posted code, what is the easiest way to get a reference do the control that fired this event so that I can check to see if the dropdown is visible?

    Here is a reference to my post:
    http://www.telerik.com/community/forums/aspnet-ajax/combobox/enter-key-not-firing-panel-s-defaultbutton-in-ie-chrome.aspx

    Thanks!!
    Thad
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 25 Oct 2010 Link to this post

    Hello Thad,

    Yes, you can verify whether the drop down is closed in the event handler if this is your requirement, e.g.
    $p._onKeyDown = function (e) {
            ...
            if (keyCode === 13 && !this.get_dropDownIsVisible())
                e.preventDefault = null;
            keyDownHandler.call(this, e);
            if (keyCode === 13 && !this.get_dropDownIsVisible()) {
                e.returnValue = oReturnValue;
                e.preventDefault = oPreventDefault;
            }
        };

    As you can see in the code above this holds a reference to the RadComboBox client-side object, so you can use it to call methods/properties of the control.

    I hope this helps.

    Regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 25 Oct 2010 Link to this post

    Thanks, Simon!

    Thad
  7. Mona
    Mona avatar
    33 posts
    Member since:
    Jul 2010

    Posted 02 Nov 2010 Link to this post

    Thanks All
  8. Sathish
    Sathish avatar
    25 posts
    Member since:
    Dec 2008

    Posted 10 Dec 2010 Link to this post

    The code snippet mentioned in this thread throws an "Too much recursion" error in firefox. Any other way of handling default button problem?
  9. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 12 Dec 2010 Link to this post

    Hello Sathish,

    You do not need this code for FireFox as there the issue does not exist. You can use $telerik.isFirefox to detect the browser.

    All the best,
    Simon
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017