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

RadNumericTextBox in RadListView

2 Answers 44 Views
Input
This is a migrated thread and some comments may be shown as answers.
Sam Bronchetti
Top achievements
Rank 1
Sam Bronchetti asked on 30 May 2012, 03:32 PM
I am trying to get the value of one of RadNumericTextBoxes in a RadListView via javascript and am having issues.  I have had to hardcode the value in the javascript and am looking for a better solution..  Here is the relevant code:
This is the RadListView.  There are repeating text boxes, then there is a total text box.  I have a javascript function that gets the values of the updated text box, then updates the total.
        <telerik:RadListView ID="rlvApproval" runat="server">
            <LayoutTemplate>
                <table>
                    <tr>
                        <td style="width: 250px;">
                        </td>
                        <td style="width: 200px; font-weight: bold;">
                        </td>
                    </tr>
                </table>
                <asp:PlaceHolder ID="itemplaceholder" runat="server" />
                <table>
                                        <tr>
                        <td style="width: 250px;">
                            <asp:Label ID="lblName" runat="server" Text="Total" Font-Bold="true" />
                        </td>
                        <td style="width: 200px; font-weight: bold;">
                            <telerik:RadNumericTextBox ID="txtTotalValue" runat="server" ReadOnly="true" DataType="System.Decimal"
                                Skin="Web20">
                                <NumberFormat DecimalDigits="0" />
                            </telerik:RadNumericTextBox>
                        </td>
                    </tr>
                      
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <table>
                    <tr>
                        <td style="width: 250px;">
                            <asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>' />
                        </td>
                        <td style="width: 250px;">
<%--                            <telerik:RadNumericTextBox ID="txtValue" runat="server" DataType="System.Decimal"
                                Skin="Web20" DbValue='<%# DataBinder.Eval(Container.DataItem, "value") %>' MaxValue="100"
                                MinValue="0" AutoPostBack="false">
                                <NumberFormat DecimalDigits="0" />
                            </telerik:RadNumericTextBox>--%>
                                                        <telerik:RadNumericTextBox ID="txtValue" runat="server" DataType="System.Decimal"
                                Skin="Web20" DbValue='<%# DataBinder.Eval(Container.DataItem, "value") %>' MaxValue="100"
                                MinValue="0" AutoPostBack="false" >
                                <NumberFormat DecimalDigits="0" />
                                <ClientEvents OnValueChanged="ValidateWeighting" />
                            </telerik:RadNumericTextBox>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            <EmptyDataTemplate>
                <div class="message">
                    <asp:Label ID="lblEmptyMessage" runat="server" SkinID="messageBig" Text="Error loading approval information..." />
                </div>
            </EmptyDataTemplate>
        </telerik:RadListView>
The javascript function is:
function ValidateWeighting(sender, eventArgs) {
    var object = document.getElementById('ctl00_ContentPlaceHolder1_Weighting1_rlvApproval_txtTotalValue');
    //var object = $find(sender.get_id().replace("txtValue", "txtTotalValue"));
    var object2 = document.getElementById('<%= rlvApproval.ClientID %>');
    var current = eval(object.value);
    var old = eventArgs.get_oldValue();
    var newval = eventArgs.get_newValue();
    var tmp = current + (newval - old);
    if (tmp == 100) {
        document.getElementById('<%= btnSave.ClientID %>').disabled = false;
    }
    else {
        document.getElementById('<%= btnSave.ClientID %>').disabled = true;
    }
    object.value = tmp;
}

How do I get the value of txtTotalValue.  I have tried the solution I have seen elsewhere, but am getting errors.  Any idea?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 May 2012, 10:49 AM
Hi,

Try the following code snippet.

JS:
<script type="text/javascript" >
        function ValidateWeighting(sender, eventArgs)
        {
            var object2 = $find("<%=rlvApproval.ClientID %>");
            var current = object2._findChildControl("txtTotalValue").get_value();
            var old = eventArgs.get_oldValue();
            var newval = eventArgs.get_newValue();
            var tmp = current + (newval - old);
            var btn = object2._findChildControl("btnSave");
            if (tmp == 100)
            {
                btn.set_enabled(false);
            }
            else
            {
                btn.set_enabled(true);
            }
            object2._findChildControl("txtTotalValue").set_value(tmp);
        }
</script>

Hope this helps.

Thanks,
Princy.
0
Sam Bronchetti
Top achievements
Rank 1
answered on 31 May 2012, 01:53 PM
Thanks, that helped.  I modified the new function to the following and it worked.
function ValidateWeighting(sender, eventArgs) {
           var object2 = $find("<%= rlvApproval.ClientID %>");
           var object = object2._findChildControl("txtTotalValue");
           var current = eval(object.get_value());
           var old = eventArgs.get_oldValue();
           var newval = eventArgs.get_newValue();
           var tmp = current + (newval - old);
           if (tmp == 100) {
               document.getElementById('<%= btnSave.ClientID %>').disabled = false;
           }
           else {
               document.getElementById('<%= btnSave.ClientID %>').disabled = true;
           }
           object.set_value(tmp);
       }
Tags
Input
Asked by
Sam Bronchetti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sam Bronchetti
Top achievements
Rank 1
Share this question
or