Autopostback and RadNumericTextBox

3 posts, 1 answers
  1. alphonse joseph
    alphonse joseph avatar
    9 posts
    Member since:
    Aug 2009

    Posted 16 Feb 2010 Link to this post

    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. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 17 Feb 2010 Link to this post

    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.
  3. alphonse joseph
    alphonse joseph avatar
    9 posts
    Member since:
    Aug 2009

    Posted 17 Feb 2010 Link to this post

    Hi Veli,
         Thanks for the nice information regarding the issue.

    Alphonse

Back to Top