Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

javaScript Not Working With UpdatePanel ASP.NET

$
0
0

Hi everyone

I'm new in asp.net, I have a problem in using javaScript with update panel, I will appreciate if any body help

I have a textbox and listbox, the textbox filter listbox values using following javascript codes:

<script type="text/javascript">

        var ddlText2, ddlValue2, ddl, ddl2, lblMesg;

        function CacheItems() {
            ddlText2 = new Array();
            ddlValue2 = new Array();
            ddl2 = document.getElementById("<%=lstbCourses.ClientID %>");

            for (var i = 0; i < ddl2.options.length; i++) {
                ddlText2[ddlText2.length] = ddl2.options[i].text;
                ddlValue2[ddlValue2.length] = ddl2.options[i].value;
            }
        }

        window.onload = CacheItems;

        function FilterItems2(value) {
            document.getElementById('<%=lstbCourses.ClientID%>').selectedIndex = -1;
            ddl2.options.length = 0;
            for (var i = 0; i < ddlText2.length; i++) {
                if (ddlText2[i].toLowerCase().indexOf(value) != -1) {
                    AddItem2(ddlText2[i], ddlValue2[i]);
                }
            }
            lblMesg.innerHTML = ddl2.options.length + " items found.";
            if (ddl2.options.length == 0) {
                AddItem2("No items found.", "");
            }
        }

        function AddItem2(text, value) {
            var opt = document.createElement("option");
            opt.text = text;
            opt.value = value;
            ddl2.options.add(opt);
        }</script>

and here is the textbox and the list box.

<asp:TextBox ID="TextBox1" runat="server" onkeyup="FilterItems2(this.value)" Width="148px"></asp:TextBox><br /><br /><asp:ListBox ID="lstbCourses" runat="server" Height="172px" Width="200px" AutoPostBack="True"
                                DataSourceID="sqdsFields" DataTextField="FieldName" DataValueField="FieldSerial"></asp:ListBox>

They work fine in normal page, but when i embed the listbox and the textbox inside update panel, only run first time, after selecting a value from listbox they will not work.

following code with updatepanel not working

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:TextBox ID="TextBox1" runat="server" onkeyup="FilterItems2(this.value)" Width="148px"></asp:TextBox><br /><br /><asp:ListBox ID="lstbCourses" runat="server" Height="172px" Width="200px" AutoPostBack="True"
                DataSourceID="sqdsFields" DataTextField="FieldName" DataValueField="FieldSerial"></asp:ListBox><asp:SqlDataSource ID="sqdsFields" runat="server" ConnectionString="<%$ ConnectionStrings:amarefarsdbConnectionString %>"
                SelectCommand="SELECT FieldSerial, FieldName FROM eduFieldOfStudy ORDER BY FieldName"></asp:SqlDataSource></ContentTemplate></asp:UpdatePanel><asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
        DisplayAfter="50"><ProgressTemplate><div><asp:Image ID="imgProgress" ImageUrl="~/Icons/ajax-loader.gif" runat="server" /></div></ProgressTemplate></asp:UpdateProgress>

I see in internet problem is due to postback of update panel, but could not resolve.

Plase help

thank you

regards hiraz


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>