RadGrid OnSortCommand event triggered by Enter Key

2 posts, 0 answers
  1. Don
    Don avatar
    16 posts
    Member since:
    May 2011

    Posted 20 Aug 2015 Link to this post

    Hi there,

    The OnItemCommand, OnSortCommand got triggered unexpectly when pressing enter key in a textbox. Here is my scenario:

    1 Click in ​a textbox below a RadGrid.

    2 Press Enter key, OnItemCommand, OnSortCommand wil be triggered.

    However,  as soon as I remove the HeaderImageUrl property in telerik:GridTemplateColumn, everything works perfectly.

    Please see the demo code below:


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestEnterKey.aspx.cs" Inherits="TestEnterKey" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <form id="form1" runat="server">
            <div style="margin-bottom:20px;">
                <asp:scriptmanager id="ScriptManager1" runat="server">
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" AllowSorting="True" OnItemCommand="grid_RowCommand"  OnSortCommand="grid_SortCommand"
                    GridLines="None" Width="800px" AllowFilteringByColumn="true" EnableLinqExpressions="false" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource" ShowFooter="True">
                    <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" AllowFilteringByColumn="true"
                    ShowFooter="True" TableLayout="Auto">
                            <telerik:GridTemplateColumn DataField="Freight"  HeaderText="Freight" SortExpression="Freight" HeaderImageUrl="~/images/datePickerPopup.png" AutoPostBackOnFilter="true" CurrentFilterFunction="GreaterThanOrEqualTo"
                                        <asp:LinkButton ID="lbl_freight" runat="server" Text='<%#Eval("Freight")%>' Visible="true"/>
                            <telerik:GridTemplateColumn DataField="ShipName" HeaderText="Ship Name" SortExpression="ShipName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                                    <asp:LinkButton ID="lbl_name" runat="server" Text='<%#Eval("ShipName")%>' Visible="true"/>
            <asp:TextBox ID="tb_componentname" TextMode="SingleLine" MaxLength="250" runat="server" CssClass="STD"></asp:TextBox>



    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Text;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using Telerik.Web.UI;
    public partial class TestEnterKey : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        public class MyOrder
            public int OrderID { get; set; }
            public DateTime OrderDate { get; set; }
            public double Freight { get; set; }
            public string ShipName { get; set; }
            public string ShipCountry { get; set; }
        protected void grid_RowCommand(object sender, GridCommandEventArgs e) 
        protected void grid_SortCommand(object source, GridSortCommandEventArgs e)
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        private void LoadData()
            MyOrder _order1 = new MyOrder();
            _order1.OrderID = 1;
            _order1.OrderDate = new DateTime(2014, 1, 18);
            _order1.Freight = 15.61;
            _order1.ShipCountry = "Canada";
            _order1.ShipName = "David";
            MyOrder _order2 = new MyOrder();
            _order2.OrderID = 2;
            _order2.OrderDate = new DateTime(2015, 9, 12);
            _order2.Freight = 12.39;
            _order2.ShipCountry = "US";
            _order2.ShipName = "Jack";
            MyOrder _order3 = new MyOrder();
            _order3.OrderID = 3;
            _order3.OrderDate = new DateTime(2015, 6, 2);
            _order3.Freight = 6.81;
            _order3.ShipCountry = "Mexico";
            _order3.ShipName = "Howard";
            MyOrder _order4 = new MyOrder();
            _order4.OrderID = 4;
            _order4.OrderDate = new DateTime(2014, 3, 26);
            _order4.Freight = 19.92;
            _order4.ShipCountry = "Canada";
            _order4.ShipName = "William";
            MyOrder _order5 = new MyOrder();
            _order5.OrderID = 5;
            _order5.OrderDate = new DateTime(2015, 5, 15);
            _order5.Freight = 9.96;
            _order5.ShipCountry = "US";
            _order5.ShipName = "Don";
            List<MyOrder> _myList = new List<MyOrder>();
            RadGrid1.DataSource = _myList;

    Any help is much appreciated!

  2. Eyup
    Eyup avatar
    3962 posts

    Posted 24 Aug 2015 Link to this post

    Hello Don,

    Please note that when there is no defaultbutton defined for the current form or container Panel, browsers automatically assign the first closest submit control as the default button for the input elements on the page. To resolve this issue, you can place the following code snippet at the top of your page within the form tag:

    <div style="display: none;">
        <asp:Button ID="HiddenButtonID" runat="server" Text="Button"
            OnClientClick="return false;" />

    That should do the trick. Please give it a try and let me know if it works for you.

    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 Feedback Portal and vote to affect the priority of the items
Back to Top