This is a migrated thread and some comments may be shown as answers.

Default Button is not working

7 Answers 203 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mona
Top achievements
Rank 1
Mona asked on 12 Oct 2010, 07:39 AM
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>

7 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 19 Oct 2010, 03:50 PM
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
0
Thad
Top achievements
Rank 2
answered on 19 Oct 2010, 06:54 PM
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
0
Simon
Telerik team
answered on 25 Oct 2010, 01:57 PM
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
0
Thad
Top achievements
Rank 2
answered on 25 Oct 2010, 05:14 PM
Thanks, Simon!

Thad
0
Mona
Top achievements
Rank 1
answered on 02 Nov 2010, 05:54 AM
Thanks All
0
Sathish
Top achievements
Rank 1
answered on 10 Dec 2010, 07:27 PM
The code snippet mentioned in this thread throws an "Too much recursion" error in firefox. Any other way of handling default button problem?
0
Simon
Telerik team
answered on 12 Dec 2010, 04:51 PM
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.
Tags
ComboBox
Asked by
Mona
Top achievements
Rank 1
Answers by
Simon
Telerik team
Thad
Top achievements
Rank 2
Mona
Top achievements
Rank 1
Sathish
Top achievements
Rank 1
Share this question
or