NumericTextBox set Value to 0.00 if users enters null value, but do totals with value from other column.

2 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 22 Sep 2014 Link to this post

    Folks using VStudio 2010 with UI for ASP.NET AJAX Q2 2014 SP1.
    I have 3 RadNumericText Boxes (txtRadOriginalPages, txtRadCopies and txtRadCopyQty1) in a Form.
    Basically it does do Client Side Total based on txtRadOriginalPages &  txtRadCopies  and populate txtRadCopyQty1. 
    I would like to Populate txtRadCopies with 0.00 if it is null and populate the Total txtRadCopyQty1 from the Value of txtRadOriginalPages in Client Side.
    Below is my complete Code Description and attached is my desired result. 

    Thanks for any help.


    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <script runat="server">
        protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            DataTable dt = new DataTable();
            DataRow dr;
            int colsNum = 4;
            int rowsNum = 5;
            string colName = "Column";
            for (int j = 1; j <= colsNum; j++)
                dt.Columns.Add(String.Format("{0}{1}", colName, j));
            for (int i = 1; i <= rowsNum; i++)
                dr = dt.NewRow();
                for (int k = 1; k <= colsNum; k++)
                    dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
            (sender as RadGrid).DataSource = dt;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <head id="Head1" runat="server">
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="50"
            BackColor="Yellow" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" OnNeedDataSource="RadGrid_NeedDataSource">
            <MasterTableView EditMode="EditForms">
                <EditFormSettings EditFormType="Template" />
                        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                            <script type="text/javascript">
                                //Calculate the original pages * the copies and input the result to copy quantity 
                                var ActualIndex;
                                var index;
                                var txtRadOriginalPages = null;
                                var txtRadCopies = null;
                                var txtRadCopyQty1 = null;
                                function updateTotals(sender, args) {
                                    var v1 = txtOriginalPages.get_value();
                                    var v2 = txtCopies.get_value();
                                    var finalValue = parseFloat(v1) + parseFloat(v2);
                                function setIndex(sender, args) {
                                    index = args.get_itemIndexHierarchical();
                                function setActualIndex() {
                                    ActualIndex = index;
                                function Load1(sender, args) {
                                    txtOriginalPages = sender;
                                function Load2(sender, args) {
                                    txtCopies = sender;
                                function Load3(sender, args) {
                                    txtRadCopyQty1 = sender;
                                <td align="left">
                                    <asp:Label ID="lblOriginalPages" runat="server" Text="Original Pages:"></asp:Label>
                                <td align="left">
                                    <telerik:RadNumericTextBox ID="txtRadOriginalPages" runat="server" NumberFormat-DecimalDigits="2"
                                        NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                        NumberFormat-AllowRounding="true" Type="Number">
                                        <ClientEvents OnValueChanged="updateTotals" OnFocus="setActualIndex" OnLoad="Load1" />
                                <td align="left">
                                    <asp:Label ID="lblCopies" runat="server" Text="Copies:"></asp:Label>
                                <td align="left">
                                    <telerik:RadNumericTextBox ID="txtRadCopies" runat="server" NumberFormat-DecimalDigits="2"
                                        NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                        NumberFormat-AllowRounding="true" Type="Number">
                                        <ClientEvents OnValueChanged="updateTotals" OnFocus="setActualIndex" OnLoad="Load2" />
                                <td align="left">
                                    <asp:Label ID="lblCopyQty1" runat="server" Text="Original Pages + Copy:"></asp:Label>
                                <td align="left">
                                    <telerik:RadNumericTextBox ID="txtRadCopyQty1" runat="server" NumberFormat-DecimalDigits="2"
                                        NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                        NumberFormat-AllowRounding="true" Type="Number">
                                        <ClientEvents OnLoad="Load3" />
                                <td align="left">
                                    <asp:Label ID="lblInkType1" runat="server" Text="Ink Type 1:"></asp:Label>
                                <td align="right" colspan="6">
                                    <asp:ImageButton ID="ImageButtonDemoMainUpdateInsert" ToolTip='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                        runat="server" ImageUrl="~/Images/GridUpdateEditInsert.gif" />
                                    <asp:ImageButton ID="ImageButtonDemoMainCancelUpdateInsert" ToolTip="Cancel" CommandName="Cancel"
                                        CausesValidation="false" runat="server" ImageUrl="~/Images/GridCancelEditInsert.gif" />
  2. Konstantin Dikov
    Konstantin Dikov avatar
    1743 posts

    Posted 25 Sep 2014 Link to this post


    I have tested the scenario that you have on my end and having in mind your requirement, could you please apply the following change within the Load2 handler and see if that is the result that you need to achieve:
    function Load2(sender, args) {
        txtCopies = sender;
        if (!sender.get_value()) {
            setTimeout(function () {

    Let me know if there are other questions on this matter.

    Konstantin Dikov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top