Rad NumericInput Box not retain client-side set values.

9 posts, 0 answers
  1. Brian
    Brian avatar
    3 posts
    Member since:
    May 2011

    Posted 10 May 2011 Link to this post

    I have an asp.net web page with several groups numeric input boxes on it. Each group has a  subtotal box (numeric input) that store a summed value that is calculated through on page javascript. This all functions correctly and displays correct as well. However, when the code behind executes, the subtotal boxes, the ones which get their values from javascript, are treated as if no value was assigned to them. All the other user entered values from the numeric inputs come through just fine.
  2. Martin
    Admin
    Martin avatar
    811 posts

    Posted 11 May 2011 Link to this post

    Hello Brian,

    Could you please verify whether you are setting the RadNumericTextBox value using its Client-side object's set_value() property?

    I hope this helps.

    Greetings,
    Martin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian
    Brian avatar
    3 posts
    Member since:
    May 2011

    Posted 11 May 2011 Link to this post

    //Sample JavaScript
    function CalculateAin(sender, eventArgs) {
              var Numericbox = $find("<%=SubtotalPremSubjAssessment_box.ClientID %>");
              var i = sender.get_value();
              Numericbox .set_value(Numericbox .get_value() - i);
              CalculateC(i, false);
     }

    //Sample Rad Input Element
    <telerik:RadNumericTextBox runat="server"  ReadOnly="true" ID="SubtotalPremSubjAssessment_box" SkinID="CurrencyOnlyBox"
    Width="135px" Value="0" DataType="System.Decimal" >
    <clientevents onvaluechanged="CalculateE" />
    </telerik:RadNumericTextBox>

    //Sample C# Code-behind (NOTE: this is where the problem is, the value assigned from the JavaScript is ignored )
    command.Parameters.AddWithValue("@SubtotalPremSubjAssessment", SubtotalPremSubjAssessment_box.Value); //This always returns the default value specified above in sample HTML; It returns null when the default value has been omitted.

    SubtotalPremSubjAssessment_box returns it's default value of 0 when called from code behind no matter what is displayed in the NumericBox. The input box always displays correctly and as expected. I am completely lost on this issue, i can't find any relevant info anywhere else, please help if you can.

    Also when i remove the readonly attribute or set it to true and manually enter a value into that numeric input, codebehind gets correct value.
  5. Martin
    Admin
    Martin avatar
    811 posts

    Posted 12 May 2011 Link to this post

    Hello Brian,

    Could you please check the CalculateAin function one more time. Note the highlighted rows bellow where "sender" and "Numericbox" are the same object and subtracting the value from itself would always result in 0:


    function CalculateAin(sender, eventArgs) {
              var Numericbox = $find("<%=SubtotalPremSubjAssessment_box.ClientID %>");
              var i = sender.get_value();
              Numericbox .set_value(Numericbox .get_value() - i);
              CalculateC(i, false);
     }


    Meanwhile you can try the code bellow that demonstrates that RadNumericTextBox functions as expected:

    <%@ Page Language="C#" %>
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="mainForm" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <script type="text/javascript">
            function CalculateE(sender, args)
            {
            }
            function MyClick()
            {
                var numericTextBox = $find("SubtotalPremSubjAssessment_box");
                numericTextBox.set_value(parseFloat(numericTextBox.get_value()) - 1);
            }
        </script>
        <script type="text/C#" runat="server">
            protected void Button1_Click(object sender, EventArgs e)
            {
                Response.Write(SubtotalPremSubjAssessment_box.Value);
            }
        </script>
        <telerik:RadNumericTextBox runat="server" ReadOnly="true" ID="SubtotalPremSubjAssessment_box"
            Width="135px" Value="0" DataType="System.Decimal">
            <ClientEvents OnValueChanged="CalculateE" />
        </telerik:RadNumericTextBox>
        <input type="button" id="Button2" value="Set value" onclick="MyClick()" />
        <asp:Button Text="Get value" ID="Button1" OnClick="Button1_Click" runat="server" />
        </form>
    </body>
    </html>

    I hope this helps.

    Greetings,
    Martin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Brian
    Brian avatar
    3 posts
    Member since:
    May 2011

    Posted 12 May 2011 Link to this post

    Actually the code works fine according to the display., That was just one sample script snip-it from the page to highlight how I am calling the numeric input. The issue is that the numeric input receiving the results of the calculations (not user input) displays as null or the default 0 value when initialized when I try to call it from the server side C# code to save it to the database. All script assigned values behave like this, all manually entered user data not calculated by scripts returns to the server side correctly and will get saved in the database.

    I finally found the solution. The client side script was not executing when the server side need it to. Added a RadAjaxManager to the page and problem was solved.


    EDIT: Okay, so after a little more testing, the AjaxManager only fixed the first occurrence of this issue. I have several boxes that take javascript entered values.
  7. Resopi
    Resopi avatar
    4 posts
    Member since:
    Jun 2013

    Posted 31 Jul 2013 Link to this post

    Hellow,

    i have the same problem, seaching for solution i found this old topic thats is Exactly problem...

    Making some test if the radcontrol seted as readonly i cant get the value(seted by set_value on JS) on codebehind, i removed the readonly and put enabled false and thats work. but i need use readonly becuse my user didnt like disabled aspect.

    anyone know this inssue?

    tkx!
  8. Martin
    Admin
    Martin avatar
    811 posts

    Posted 01 Aug 2013 Link to this post

    Hello Resopi,

    I have tried to replicate the issue utilizing the code bellow, but the value is successfully retrieved from the server. Please review it and let me know whether I miss something.

    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="Sm1">
        </asp:ScriptManager>
        <script runat="server">
            protected void Button1_Click(object sender, EventArgs e)
            {
                L1.Text = "Text: " + RadNumericTextBox1.Text;
                L2.Text = "Value: " + RadNumericTextBox1.Value.ToString();
            }
        </script>
        <script type="text/javascript">
            function ClientClick()
            {
                var numTextBox = $find("<%= RadNumericTextBox1.ClientID %>");
                var num = Math.random();
                numTextBox.set_value(num * 100);
            }
        </script>
        <asp:Button Text="SetValue" OnClientClick="ClientClick();return false;" runat="server" />
        <asp:Button Text="PostBack" ID="Button1" OnClick="Button1_Click" runat="server" />
        <telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox1" ReadOnly="true"></telerik:RadNumericTextBox>
        <asp:Label Text="" ID="L1" runat="server" />
        <asp:Label Text="" ID="L2" runat="server" />
        </form>
    </body>
    </html>

    I hope this helps.

    Regards,
    Martin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  9. Don
    Don avatar
    38 posts
    Member since:
    Oct 2006

    Posted 26 Sep 2013 Link to this post

    My problem is similar but slightly more complex.

    I am using a Numeric-Input with it's type set to "currency" while inside a RadGrid in edit mode.
    Normal usage is working fine but my functionality requires a keyboard HotKey/AccessKey for the submit button.

    Scenario:
    Users input data into the grid primarily using only the keyboard.
    This particular input is the LAST column in the grid so they type in a dollar amount and
    then submit the form using the hotkey associated to the Submit button ("Access Key").

    <asp:button id="btnAdd" accessKey="A"  runat="server" ToolTip="Press Alt+A to Add Row" Text="Add Row" onclick="btnAdd_Click"></asp:button

    the grid does not recognize a value inside the (edit-mode) numeric-Input field unless they TAB OFF the control. I have been able to trap this event (btnAdd_Click)  while firing on the client, actually trapping OnBlur fired from within the Numeric-Input which occurs prior to the btnAddRow event, but the Grid still shows as $0 for this control on the server postback.

  10. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 01 Oct 2013 Link to this post

    Hi Don,

    This issue was fixed in the later versions. Try out our public beta for the next release. Check the changes here:
    http://www.telerik.com/products/aspnet-ajax/whats-new/release-history/q3-2013-beta-version-2013-3-926.aspx

    Regards,
    Vasil
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017