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

Autopostback and RadNumericTextBox

2 Answers 184 Views
Input
This is a migrated thread and some comments may be shown as answers.
alphonse joseph
Top achievements
Rank 1
alphonse joseph asked on 16 Feb 2010, 07:01 AM
Hi,
    I am using RadNumericTextBox inside the <edititemtemplate> tag of a RadGrid. I have set autopostback property of RadNumericTextBox to false.  Still when I press Enter key postback happens.  Given below is my code:

 <telerik:RadGrid ID="grdTrans" GridLines="None"  AutoGenerateColumns="false" Height="500px"
           AutoGenerateEditColumn="false" AutoGenerateDeleteColumn="false"
           runat="server"  OnCancelCommand="grdTrans_CancelCommand"
           AllowPaging="false" AllowSorting="false"
           OnDeleteCommand="grdTrans_DeleteCommand"  OnUpdateCommand="grdTrans_UpdateCommand"
           onneeddatasource="grdTrans_NeedDataSource"
           oninsertcommand="grdTrans_InsertCommand"
           onitemdatabound="grdTrans_ItemDataBound"
           oneditcommand="grdTrans_EditCommand" >
            <MasterTableView Name="master"  EditMode="InPlace" GridLines="None" DataKeyNames="accid" CommandItemDisplay="Bottom" >
                <Columns>
                  <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>

<telerik:GridTemplateColumn  HeaderText="Debit" UniqueName="debit" DataType="System.Decimal" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right" >
                        <ItemTemplate>
                                       <asp:Label ID="lblDbAmt" Text= '<%# Eval("dbamt") %>' CssClass="labels"   runat="server"> </asp:Label>
                        </ItemTemplate>
           
                       <EditItemTemplate>
                              <telerik:RadNumericTextBox ID="txtDbAmt" Text  = '<%# bind("dbamt") %>' MinValue="0" MaxValue="99999999.99" MaxLength="11" DataType="System.Decimal" Culture="en-GB"  AutoPostBack="false" ClientEvents-OnKeyPress="KeyPressed" EnabledStyle-HorizontalAlign="Right" runat="server">                   
                            <NumberFormat AllowRounding="false" DecimalDigits="2" DecimalSeparator="." GroupSeparator="," GroupSizes="3"   />
                             </telerik:RadNumericTextBox>            
           
                       </EditItemTemplate>
 </telerik:GridTemplateColumn>   

I had to use the following javascript function to avoid postback:
 function KeyPressed(ctrl, e) {
             if (e.get_domEvent().rawEvent.keyCode == 13) { //enter  
                 //special handling (focus other control and so on) here  
                 e.get_domEvent().preventDefault();
                 e.get_domEvent().stopPropagation();
             }

Is there any workaround other than using the above javascript.

Alphonse



2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 17 Feb 2010, 03:31 PM
Hi alphonse,

The behavior you are getting is caused by the ASP.NET form itself, where on Enter, the form is posted from the first submit button in it. For more info:

Enter key in ASP.NET

To prevent the Enter key, the approach you have taken is the right one for RadGrid.

All the best,
Veli
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.
0
alphonse joseph
Top achievements
Rank 1
answered on 18 Feb 2010, 05:55 AM
Hi Veli,
     Thanks for the nice information regarding the issue.

Alphonse

Tags
Input
Asked by
alphonse joseph
Top achievements
Rank 1
Answers by
Veli
Telerik team
alphonse joseph
Top achievements
Rank 1
Share this question
or