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

Rad NumericInput Box not retain client-side set values.

8 Answers 384 Views
Input
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 2
Brian asked on 10 May 2011, 09:18 PM
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.

8 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 11 May 2011, 08:45 AM
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.

0
Brian
Top achievements
Rank 2
answered on 11 May 2011, 03:06 PM
//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.
0
Martin
Telerik team
answered on 12 May 2011, 09:40 AM
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.

0
Brian
Top achievements
Rank 2
answered on 12 May 2011, 04:27 PM
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.
0
Resopi
Top achievements
Rank 1
answered on 31 Jul 2013, 01:21 PM
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!
0
Martin
Telerik team
answered on 01 Aug 2013, 07:26 AM
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.
0
Don
Top achievements
Rank 2
answered on 27 Sep 2013, 12:26 AM
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.

0
Vasil
Telerik team
answered on 01 Oct 2013, 08:24 AM
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.
Tags
Input
Asked by
Brian
Top achievements
Rank 2
Answers by
Martin
Telerik team
Brian
Top achievements
Rank 2
Resopi
Top achievements
Rank 1
Don
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or