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

Edit Mode auto show

9 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ALEX
Top achievements
Rank 1
ALEX asked on 11 Feb 2012, 06:38 AM
Hi Team,

    I'm facing with grid edit mode(InPlace or Popup or EditForm) is always auto fire when i press enter key in search text box. My grid is using OnNeedDataSource property. Problem is become from "RadAjaxManager". If i set setting at ajamanager
<telerik:AjaxSetting AjaxControlID="_btnSearch" EventName="OnClick" >
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
RadGrid Edit Form is auto fired. If i remove it, it's ok.

Code Aspx.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server" autocomplete="false">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager" runat="server">
            </telerik:RadScriptManager>
            <!-- content start -->
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="_btnSearch" EventName="OnClick" >
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
            </telerik:RadAjaxLoadingPanel>
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%" Width="300px" OnLoad="RadAjaxPanel1_Load"
             >
                <table>
                    <tr>
                        <td style="width: 150px;">
                            Search By</td>
                        <td style="width: 5px;">
                            :</td>
                        <td style="width: 150px;">
                            <asp:DropDownList ID="_cboSearchBy" runat="server" Width="150px">
                            </asp:DropDownList>
                        </td>
                        <td style="width: 25px">
                            <asp:TextBox ID="_txtPrefix" runat="server" Width="25px" AutoPostBack="false" AutoCompleteType="none"></asp:TextBox></td>
                        <td style="width: 200px;">
                            <asp:TextBox ID="_txtFind" runat="server" Width="200px" AutoPostBack="false" AutoCompleteType="none"></asp:TextBox></td>
                        <td style="width: 25px">
                            <asp:TextBox ID="_txtSuffix" runat="server" Width="25px" AutoPostBack="false" AutoCompleteType="none"></asp:TextBox></td>
                        <td style="width: 50px">
                            <asp:Button ID="_btnSearch" runat="server" Text="Search" Width="50px" OnClick="_btnSearch_Click" />
                        </td>
                    </tr>
                </table>
            </telerik:RadAjaxPanel>
            <telerik:RadGrid ID="RadGrid1" Width="97%" AllowPaging="True" PageSize="15" runat="server"
                AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" GridLines="None" OnItemCommand="RadGrid1_ItemCommand">
                <MasterTableView Width="100%" EditMode="" AllowAutomaticUpdates="false">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                            EditText="Edit" HeaderStyle-Width="30" ItemStyle-Width="30" HeaderStyle-HorizontalAlign="center"
                            ItemStyle-HorizontalAlign="center">
                        </telerik:GridEditCommandColumn>
                    </Columns>
                </MasterTableView>
                <PagerStyle Mode="NextPrevAndNumeric" />
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>
            <!-- content end -->
        </div>
    </form>
</body>
</html>

Code Behind

public DataTable GetDataTable(string query)
 {
     String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
     SqlConnection conn = new SqlConnection(ConnString);
     SqlDataAdapter adapter = new SqlDataAdapter();
     adapter.SelectCommand = new SqlCommand(query, conn);
 
     DataTable myDataTable = new DataTable();
 
     conn.Open();
     try
     {
         adapter.Fill(myDataTable);
     }
     finally
     {
         conn.Close();
     }
 
     return myDataTable;
 }
 
 protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
     RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");
 }
  
 protected void _btnSearch_Click(object sender, EventArgs e)
 {
     if (_txtFind.Text.Trim()!="")
         RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers where CustomerID='" + _txtFind.Text.Trim() + "'");
     else
         RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers");
     RadGrid1.Rebind();
 }
  
 protected void RadAjaxPanel1_Load(object sender, EventArgs e)
 {
 }
  
 protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
 {
     //e.Canceled = true;
 }


Anything wrong at my code. . Kindly please reply to me. Sorry! my title is wrong! Problem is "GridEditCommandColumn auto fire".

sample lnk :Sample Code

Regards,

9 Answers, 1 is accepted

Sort by
0
ALEX
Top achievements
Rank 1
answered on 13 Feb 2012, 03:41 AM
Hi Team,

         Can anyone answer to my question? Problem is auto fire event inside grid when i keypress in text box. I need urgent.

I'm using "RadControls for ASP.NET AJAX Q3 2010".

0
ALEX
Top achievements
Rank 1
answered on 13 Feb 2012, 12:29 PM
Hi,

           Does anybody don't know it? :(

Regards,
0
Casey
Top achievements
Rank 1
answered on 13 Feb 2012, 05:16 PM
Hi Alex,

What exactly happens when you hit Enter when in the textbox? What do you want it to do when you hit enter in the textbox?

Casey
0
ALEX
Top achievements
Rank 1
answered on 14 Feb 2012, 02:22 AM
Hi Casey,

           Morning! Thanks for your answer and question. When user hit the textbox we no need to do anything cursor should be stay at textbox. Problem is when i enter the at textbox, grid event is auto fired. Eg. I don't use editcommand but i used command button. Those command onClient Client call the js "js:alert('Hello');. Ok! When i enter at textbox cursor is point to those command button fired the event.
What i want is when the user enter at textbox, cursor should be stay at there and don't want to call grid event.

          Kindly, please advice to me.


Regards,
Alex
0
Casey
Top achievements
Rank 1
answered on 14 Feb 2012, 02:34 PM
Hi Alex,

I am having difficulties getting the OnKeyPress event canceled for an asp:TextBox, but here is how you can cancel the KeyPress event in a RadTextBox if enter is pressed.

You should be able to attach the OnKeyPress event to the RadTextBox, and then check the key code to determine if the enter key was pressed. If enter was the key firing the event, then you can cancel the event. The following code should accomplish what you are looking for. Add the following to the RadTextBox definition: ClientEvents-OnKeyPress="keyPress"

function keyPress(sender, eventArgs) {
        var c = eventArgs.get_keyCode();
        if (c == 13) {
            eventArgs.set_cancel(true);
       }
}

I hope this helps!
Casey
0
Accepted
Casey
Top achievements
Rank 1
answered on 14 Feb 2012, 03:31 PM
Hi Alex,

I found how to do it with an asp:TextBox.

I hope this helps!

Casey

protected void Page_Load(object sender, EventArgs e)
{
        if (!Page.IsPostBack)
        {
            TextBox1.Attributes.Add("onkeydown", "return (event.keyCode!=13);");
        }
}
0
ALEX
Top achievements
Rank 1
answered on 14 Feb 2012, 05:44 PM
Hi Casey,

           Thanks for your research and reply. It's Great Work. Hope this topic help to others!

Noted: Why cursor always point to grid command button (CommandItem btn also) and fired it. It's bug or what.

Below is my method. Your code is better then this one.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="_btnSearch" EventName="OnClick">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="_txtFind">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="_txtFind" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%" Width="300px"
            OnLoad="RadAjaxPanel1_Load">
            <telerik:RadAjaxPanel runat="server" ID="_pnlSearch">
                <table>
                    <tr>
                        <td style="width: 150px;">
                            Search By
                        </td>
                        <td style="width: 5px;">
                            :
                        </td>
                        <td style="width: 150px;">
                            <asp:DropDownList ID="_cboSearchBy" runat="server" Width="150px">
                            </asp:DropDownList>
                        </td>
                        <td style="width: 25px">
                            <asp:TextBox ID="_txtPrefix" runat="server" Width="25px" AutoPostBack="false" AutoCompleteType="none"></asp:TextBox>
                        </td>
                        <td style="width: 200px;">
                            <asp:TextBox ID="_txtFind" runat="server" Width="200px" AutoPostBack="true" AutoCompleteType="none"></asp:TextBox>
                        </td>
                        <td style="width: 25px">
                            <asp:TextBox ID="_txtSuffix" runat="server" Width="25px" AutoPostBack="false" AutoCompleteType="none"></asp:TextBox>
                        </td>
                        <td style="width: 50px">
                            <asp:Button ID="_btnSearch" runat="server" Text="Search" Width="50px" OnClick="_btnSearch_Click" />
                        </td>
                    </tr>
                </table>
            </telerik:RadAjaxPanel>
        </telerik:RadAjaxPanel>

Regards,
Alex
0
Tsvetina
Telerik team
answered on 15 Feb 2012, 09:28 AM
Hello Alex,

I am not absolutely sure what the issue you describe is. If it is that on Enter key press a certain button on the grid is getting pressed, it is most probably due to the default button feature of the <form> element. You can read more in this blog post:
http://marekblotny.blogspot.com/2009/03/defaultbutton-deal-with-users-hitting.html

If this is not what you had in mind, please elaborate a little more on the problem.

Regards,
Tsvetina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
ALEX
Top achievements
Rank 1
answered on 21 Feb 2012, 03:14 PM
Hi Tsvetina,

         Thanks for your info.

Regards,
Alex
Tags
Grid
Asked by
ALEX
Top achievements
Rank 1
Answers by
ALEX
Top achievements
Rank 1
Casey
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or