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

[Solved] RadGrid ItemCommand fires on TextBox change

2 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frank Lemmen
Top achievements
Rank 1
Frank Lemmen asked on 18 Dec 2009, 09:18 AM

I am using RadControls for ASP.NET AJAX.

 

I have implemented a simple RadGrid, which consists of a GridTemplateColumn holding a RadNumericTextBox and an ImageButton.

 

If a value is written into the text box and enter is pressed, the “ontextchanged” event fires and operation “value_TextChanged” is called within the code behind. But in addition, the operation “RadGrid_ItemCommand” is called within code behind and the event arguments indicates, that command “WasteCommand” has been invoked, which is not true.

 

I have investigated, that the problem does not occur if a button is placed on the page in addition to the grid.

 

<body>

    <form id="form1" runat="server">

   

    <%--<asp:Button ID="Button1" runat="server" Text="Button" />--%>

   

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

    </telerik:RadScriptManager>

   

   

<telerik:RadGrid ID="RadGrid_KVA"

    OnNeedDataSource="RadGrid_NeedDataSource"

    OnItemCommand="RadGrid_ItemCommand"

    runat="server">

   

    <MasterTableView  DataKeyNames="id" AutoGenerateColumns="False">                     

        <Columns>                                                 

           <telerik:GridTemplateColumn HeaderText="Value" UniqueName="columnValue">

           <ItemTemplate>    

               <telerik:RadNumericTextBox ID="Value" runat="server"  ontextchanged="value_TextChanged" Width="40px" >                       

               </telerik:RadNumericTextBox>

               <asp:ImageButton ID="WasteButton" runat="server" ImageUrl="btnCalculator.png"

                CommandName="WasteCommand" />                                   

           </ItemTemplate>

           </telerik:GridTemplateColumn>                                                                                  

        </Columns>                       

    </MasterTableView>               

</telerik:RadGrid>

   

    </form>

</body>

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 21 Dec 2009, 08:28 AM
Hello Frank,

If you do not have any other buttons on your page the default postback button is your ImageButton . When the user press “Enter” Command event is fired on grid from the ImageButton. Possible approach to avoid this would be to add hidden button on the page:

<asp:Button ID="ButtonID" style="display:none;" runat="server" />

and set  this button’s  id to defaultbutton form property:

<form defaultbutton="ButtonID" id="form1" runat="server">

I hope this helps.

Sincerely yours,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Frank Lemmen
Top achievements
Rank 1
answered on 29 Dec 2009, 11:23 AM

Hello Radoslav,

 

Thank you very much for your help, your solution works fine.

 

Regards,

Frank

Tags
Grid
Asked by
Frank Lemmen
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Frank Lemmen
Top achievements
Rank 1
Share this question
or