RadNumericTextBox onKey up enable/disable dropdownlist

6 posts, 0 answers
  1. Borislava
    Borislava avatar
    15 posts
    Member since:
    Oct 2012

    Posted 19 Dec 2013 Link to this post

    <telerik:RadNumericTextBox ID="txtStuAdds" Width="70px" Value="0" DbValue='<%# Bind("StudentAdds") %>'
                                                          runat="server" Type="Number" NumberFormat-DecimalDigits="0" Onkeyup="txtStudAddValueChanged()" >
                                                      </telerik:RadNumericTextBox>
                                                                                                 <asp:DropDownList runat="server" ID="ddlStuAddStatus" />
    I have RadNumericTextBox how can I disable/enable dropdown based on a value entered? if textbox is empty or 0 enable drop down else disable.
    <script type="text/javascript">
        function txtStudAddValueChanged(sender, eArgs) {
            var numericTextBox = $find(sender.id);
            var value = numericTextBox.get_value();
            alert(value);
        }
    I have the following script but it failed on var numericTextBox = $find(sender.id);
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Dec 2013 Link to this post

    Hi Borislava,

    Please try the following JavaScript to access the RadNumericTextBox in 'txtStudAddValueChanged' event.

    JavaScript:
    <script type="text/javascript">
        function txtStudAddValueChanged() {
            var numericTextBox = $find("<%=txtStuAdds.ClientID %>");
            var value = numericTextBox.get_value();
            alert(value);
        }
    </script>

    Let me know if you have any concern.
    Thanks,
    Shinu.

  3. Borislava
    Borislava avatar
    15 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2013 Link to this post

    Getting a complier ex:
    BC30451: 'txtStuAdds' is not declared. It may be inaccessible due to its protection level.

    NumericTextBox inside raggrid edit template.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Dec 2013 Link to this post

    Hi Borislava,

    Please try the following code snippet to access the value in the RadNumericTextBox on 'txtStudAddValueChanged event.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="grid1_ItemDataBound"
        AutoGenerateEditColumn="true">
        <MasterTableView>
            <Columns>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="txtStuAdds" Width="70px" Value="0" runat="server"
                            Type="Number" NumberFormat-DecimalDigits="0" Onkeyup="txtStudAddValueChanged(this)"
                            DbValue='<%# Bind("OrderID") %>'>
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    JavaScript:
    <script type="text/javascript">
        function txtStudAddValueChanged(sender) {
            alert(sender.control.get_value());
        }
    </script>

    Hope this will helps you.
    Thanks,
    Shinu.
  5. Borislava
    Borislava avatar
    15 posts
    Member since:
    Oct 2012

    Posted 26 Dec 2013 Link to this post

    Now I am able to  get value but it's 1 value behind.
    So if I enter 2 and 3 only 2 will show up .
    Also how can I find a dropdownlist in order to disable based on value?
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Dec 2013 Link to this post

    Hi Borislava,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <asp:DropDownList runat="server" ID="ddlStuAddStatus" />
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="grid1_ItemDataBound"
        AutoGenerateEditColumn="true">
        <MasterTableView>
            <Columns>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="txtStuAdds" Width="70px" Value="0" runat="server"
                            Type="Number" NumberFormat-DecimalDigits="0" ClientEvents-OnKeyPress="txtStudAddValueChanged"
                            DbValue='<%# Bind("OrderID") %>'>
                        </telerik:RadNumericTextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    JavaScript:
    <script type="text/javascript">
        function txtStudAddValueChanged(sender, args) {
            var dropdownlist = document.getElementById("ddlStuAddStatus");
            if (args.get_keyCharacter() == " " || args.get_keyCharacter() == "0") {
                dropdownlist.disabled = true;
            }
            else
                dropdownlist.disabled = false;
            alert(args.get_keyCharacter());
        }
    </script>

    Let me know if you have any concern.
    Thanks,
    Shinu.
Back to Top