Javascript not seeing dropdown value

3 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 20 Aug 2013 Link to this post

    I have a panel and dropdown like so
    <telerik:RadAjaxPanel runat="server" ID="panel" LoadingPanelID="loadingPanel">
    <asp:DropDownList ID="itemDrop" runat="server"></asp:DropDownList>
        </telerik:RadAjaxPanel>
        <telerik:RadAjaxLoadingPanel ID="loadingPanel" BackgroundPosition="Center" runat="server">
            <img id="Img1" alt="Loading..." src="~/images/loading.gif" runat="server" style="border: 0px;" />
        </telerik:RadAjaxLoadingPanel>

    In the code behind I attach a JS function to the onchange event of the dropdown. Here is the JS function
    function showFields(id) {
        var dd = document.getElementById(id);
        var itemArr = (dd.options[dd.selectedIndex].value).split(";;;");
         
        var perDiv = document.getElementById("percentDiv");
        var quantDiv = document.getElementById("quantityDiv");
         
        var disValue = itemArr[1];
        var item = itemArr[0];
         
        if (item == "-1") {
            perDiv.style.display = "none";
            quantDiv.style.display = "none";
        }
        else {
             
            //see if we show quantity as well
            if (disValue > 0) {
                perDiv.style.display = "block";
                quantDiv.style.display = "block";
            }
            else {
                perDiv.style.display = "none";
                quantDiv.style.display = "block";
            }//if disValue > 0
     
             
        }//if item == -1
    }

    Basically, I pass in the client id of the drop down. It then reads the value and decides whether or not to show some text boxes. They are set to display none by default. The problem I have is, when I do a post back with the ajax panel, the text boxes go back to being hidden. I am also calling this javascript function in the page load. When I remove the ajax panel, it sees the dd and keeps the text boxes visible. However, when I add the ajaxpanel back in, the textboxes go back to hidden on the postback. Any ideas why?






  2. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 22 Aug 2013 Link to this post

    Any help here, this is a little urgent.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 23 Aug 2013 Link to this post

    Hi,

    When calling a script function from the code behind and you have AJAX enabled on your page, there are some specifics:
    http://demos.telerik.com/aspnet-ajax/ajax/examples/common/recreatescripts/defaultcs.aspx

    Furthermore, you should wrap your script in RadScriptBlock:
    http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html

    Hope this helps.

    Regards,
    Eyup
    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