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

RadGrid Enter Key disable

1 Answer 240 Views
Grid
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
Hi,

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"
                        AllowFilteringByColumn="true" 
                        AllowSorting="true"
                        AllowAutomaticDeletes="false"
                        AllowAutomaticInserts="false"
                        AllowAutomaticUpdates="false"
                        AllowMultiRowEdit="false"
                        AllowPaging="true"
                        PagerStyle-Position="Bottom"
                        AutoGenerateEditColumn="false"
                        AutoGenerateDeleteColumn="false"
                        MasterTableView-AllowAutomaticDeletes="false"
                        MasterTableView-AllowAutomaticInserts="false"
                        MasterTableView-AllowAutomaticUpdates="false"
                        AllowMultiRowSelection="false"
                        GridLines="Horizontal" 
                        Skin="Outlook" PageSize="20" BorderStyle="None" 
                        onitemdatabound="GridRecordList_ItemDataBound">
                        <GroupingSettings CaseSensitive="false" />
                        <headercontextmenu>
                            <collapseanimation duration="200" type="OutQuint" />
                        </headercontextmenu>
                        <mastertableview AutoGenerateColumns="false">
                            <Columns>
                                <telerik:GridBoundColumn DataField="SourceRecordID" HeaderText="SourceRecordID" UniqueName="SourceRecordID" Display="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Application.ApplicationID" HeaderText="ApplicationID" UniqueName="ApplicationID" Display="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="DocumentCount" HeaderText="DocCount" EmptyDataText="Unknown" UniqueName="DocumentCount" Display="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Specialty.Name" HeaderText="Specialty" EmptyDataText="Unknown" SortExpression="Specialty.Name" UniqueName="Specialty">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Staff.ShortName" HeaderText="Staff Name" EmptyDataText="Unknown" SortExpression="Staff.ShortName" UniqueName="ShortName">
                                </telerik:GridBoundColumn>
                                <telerik:GridDateTimeColumn DataField="RecordDate" HeaderText="Record Date" EmptyDataText="Unknown" SortExpression="RecordDate" UniqueName="RecordDate" DataFormatString="{0:dd/MM/yyyy}" DataType="System.DateTime">
                                </telerik:GridDateTimeColumn>
                                <telerik:GridBoundColumn DataField="RecordType.DisplayName" HeaderText="Record Type" EmptyDataText="Unknown" SortExpression="RecordType.DisplayName" UniqueName="RecordType">
                                </telerik:GridBoundColumn>                                        
                            </Columns>
                            <SortExpressions>
                                <telerik:GridSortExpression FieldName="RecordDate" SortOrder="Descending" />
                            </SortExpressions>
                            <AlternatingItemStyle BackColor="#FFF4CE" Wrap="false" BorderColor="#FFECA5" BorderStyle="Solid" BorderWidth="2px" />
                            <ItemStyle Wrap="false" />
                            <rowindicatorcolumn>
                                <HeaderStyle Width="20px" BackColor="Purple" />
                            </rowindicatorcolumn>
                            <expandcollapsecolumn>
                                <HeaderStyle Width="20px" BackColor="Purple" />
                            </expandcollapsecolumn>
                        </mastertableview>
                        <filtermenu>
                            <collapseanimation duration="200" type="OutQuint" />
                        </filtermenu>
                        <ClientSettings AllowKeyboardNavigation="true"
                            AllowColumnsReorder="false" 
                            EnablePostBackOnRowClick="false"
                            Resizing-AllowColumnResize="true"
                            Scrolling-AllowScroll="true" 
                            Selecting-AllowRowSelect="true"
                            KeyboardNavigationSettings-EnableKeyboardShortcuts="true">
                                <ClientEvents OnGridCreated="GridCreated" />
                                <ClientEvents OnRowClick="GridRecordList_OnRowClick" />
                                <ClientEvents OnRowContextMenu="RowContextMenu" />
                                <ClientEvents OnKeyPress="GridRecordList_OnKeyPress" />
                        </ClientSettings>
                    </telerik:RadGrid>



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

1 Answer, 1 is accepted

Sort by
0
Tsvetina
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.

Regards,
Tsvetina
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
Tags
Grid
Asked by
Andrew Currie
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or