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

RadGrid Enter Key disable

1 Answer 240 Views
This is a migrated thread and some comments may be shown as answers.
Andrew Currie
Top achievements
Rank 1
Andrew Currie asked on 11 Oct 2010, 04:01 PM

I started off by requiring the edit panel on the RadGrid to be disabled on enter key press.  I have managed to achieve this, the panel doesn't show anymore but the problem is that I now get an Ajax postback instead (I wasn't getting this on enter keypress before).

In the OnKeyPress for my grid I call the following javascript (see below).  This does stop the edit panel appearing

Telerik version: 2009.2.826.35 VS 2008 SP1

I have a RadGrid as follows and also a RadAjaxManager so that I get a LoadingPanel for the Grid:

                    <telerik:RadGrid ClientSettings-AllowColumnsReorder="true" ID="GridRecordList"
                        runat="server" EnableLinqExpressions="true" EnableViewState="false"
                        Skin="Outlook" PageSize="20" BorderStyle="None" 
                        <GroupingSettings CaseSensitive="false" />
                            <collapseanimation duration="200" type="OutQuint" />
                        <mastertableview AutoGenerateColumns="false">
                                <telerik:GridBoundColumn DataField="SourceRecordID" HeaderText="SourceRecordID" UniqueName="SourceRecordID" Display="false">
                                <telerik:GridBoundColumn DataField="Application.ApplicationID" HeaderText="ApplicationID" UniqueName="ApplicationID" Display="false">
                                <telerik:GridBoundColumn DataField="DocumentCount" HeaderText="DocCount" EmptyDataText="Unknown" UniqueName="DocumentCount" Display="false">
                                <telerik:GridBoundColumn DataField="Specialty.Name" HeaderText="Specialty" EmptyDataText="Unknown" SortExpression="Specialty.Name" UniqueName="Specialty">
                                <telerik:GridBoundColumn DataField="Staff.ShortName" HeaderText="Staff Name" EmptyDataText="Unknown" SortExpression="Staff.ShortName" UniqueName="ShortName">
                                <telerik:GridDateTimeColumn DataField="RecordDate" HeaderText="Record Date" EmptyDataText="Unknown" SortExpression="RecordDate" UniqueName="RecordDate" DataFormatString="{0:dd/MM/yyyy}" DataType="System.DateTime">
                                <telerik:GridBoundColumn DataField="RecordType.DisplayName" HeaderText="Record Type" EmptyDataText="Unknown" SortExpression="RecordType.DisplayName" UniqueName="RecordType">
                                <telerik:GridSortExpression FieldName="RecordDate" SortOrder="Descending" />
                            <AlternatingItemStyle BackColor="#FFF4CE" Wrap="false" BorderColor="#FFECA5" BorderStyle="Solid" BorderWidth="2px" />
                            <ItemStyle Wrap="false" />
                                <HeaderStyle Width="20px" BackColor="Purple" />
                                <HeaderStyle Width="20px" BackColor="Purple" />
                            <collapseanimation duration="200" type="OutQuint" />
                        <ClientSettings AllowKeyboardNavigation="true"
                                <ClientEvents OnGridCreated="GridCreated" />
                                <ClientEvents OnRowClick="GridRecordList_OnRowClick" />
                                <ClientEvents OnRowContextMenu="RowContextMenu" />
                                <ClientEvents OnKeyPress="GridRecordList_OnKeyPress" />

                            function GridRecordList_OnKeyPress(sender, eventArgs) {
                                var e = window.event;
                                if (eventArgs.get_keyCode() == 13) {
                                    eventArgs.returnValue = false;
                                    eventArgs.cancelBubble = true;
                                    eventArgs.set_cancelBubble = true;
                                    e.cancelBubble = true;
                                    return false;

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 15 Oct 2010, 07:46 AM
Hi Andrew,

It is possible that Enter key press triggers a postback from the default button of the form which would be the first rendered button on the page. If this is so, you can try fixing this by providing an inactive default button for the current form (or Panel if RadGrid is residing in one) using the following approach:

Create an invisible button which does not do postbacks:
<asp:Button ID="Button2" runat="server" Text="" style="display: none;" OnClientClick="return false;" />

and then set it as default for the container:
<form id="form1" defaultbutton="Button2" runat="server">

I hope this solves the problem you are encountering.

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
Asked by
Andrew Currie
Top achievements
Rank 1
Answers by
Telerik team
Share this question