Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > calculate sum of to inbut box on client side
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Answered calculate sum of to inbut box on client side

Feed from this thread
  • Afshin avatar

    Posted on Jan 13, 2011 (permalink)

    I'm trying to calculate sum of two numeric input boxes, using Jscript on Client side.
    however, there is not any progress. because the error message "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)" appears.

    please help

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
                function TestCalc() {
     
                var a = $find('<%= t1.ClientID %>');
                var b = $find('<%= t1.ClientID %>');
                var c = $find('<%= t1.ClientID %>');
                c.set_value(a.get_value() + b.get_value());
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <div align="center">
            <telerik:RadNumericTextBox ID="t1" runat="server" Culture="fa-IR" Type="Currency"
                Value="0" Width="125px" ClientEvents-OnBlur="TestCalc()">
            </telerik:RadNumericTextBox>
            <br />
            <telerik:RadNumericTextBox ID="t2" runat="server" Culture="fa-IR" Type="Currency"
                Value="0" Width="125px" ClientEvents-OnBlur="TestCalc()">
            </telerik:RadNumericTextBox>
            <br />
            <telerik:RadNumericTextBox ID="t3" runat="server" Culture="fa-IR" Type="Currency"
                Value="0" Width="125px" ClientEvents-OnBlur="TestCalc()">
            </telerik:RadNumericTextBox>
        </div>
        </form>
    </body>
    </html>

  • Answer Shinu MVP avatar

    Posted on Jan 14, 2011 (permalink)

    Hello Afshin,

    Since the script is inside the head tag, you need to use RadScriptBlock as given below.

    Javascript:
    <telerik:RadScriptBlock ID="Script1" runat="server">
        <script type="text/javascript">
            function TestCalc(sender, args)
           {
          //code
            }
        </script>
    </telerik:RadScriptBlock>

    And also you can refer the following documentation or more on this.
    General Troubleshooting

    And while calling client side method of RadControls, you need not use brackets. The correct method of attaching the event shown below.

    <telerik:RadNumericTextBox ID="t1" runat="server" Culture="fa-IR" Type="Currency"
             Value="0" Width="125px" ClientEvents-OnBlur="TestCalc">
    </telerik:RadNumericTextBox>

    Thanks,
    Shinu.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > calculate sum of to inbut box on client side