asp.net - RegisterStartupScript not working with UpdatePanel and Google Visualization charts -
on asp.net page using google visualization charts inside of asp:updatepanel. user selects chart want see 2 asp:dropdownlists , c# code generates javascript , call scriptmanager.registerstartipscript(...). when page first loads first default chart (i.e. first call registerstartupscript) works , can view javascript view source. on postbacks blank chart , when go view source page didn't receive new javascript , still has old default javascript first page load. here weird behavior. if use exact same code replace google chart code alert(...); alert() fires every time , when view source script there. i've tried may different things , followed such answers here. below code , appreciated, i've had other people @ , stumped. fyi: if remove updatepanels , related items (scriptmanager , updateprogress) , use clientscript.registerstartupscript() works fine , new javascript code on page , new chart appears should.
<asp:scriptmanager id="scriptmgr" runat="server" /> <asp:updatepanel id="updatepaneldata" runat="server"> <contenttemplate> <p> <asp:dropdownlist id="plotlist" runat="server" autopostback="true" width="500px" onselectedindexchanged="plotlist_selectedindexchanged"></asp:dropdownlist> <asp:dropdownlist id="rangelist" runat="server" width="125px" style="float:right;" autopostback="true" onselectedindexchanged="rangelist_selectedindexchanged"> </asp:dropdownlist> <br /> <asp:label id="plotdescription" runat="server" width="100%"></asp:label> </p> <div id="chart_material" class="googlechart" style="width:100%;height:450px;"></div> </contenttemplate> <triggers> <asp:asyncpostbacktrigger controlid="rangelist" eventname="selectedindexchanged" /> <asp:asyncpostbacktrigger controlid="plotlist" eventname="selectedindexchanged" /> </triggers> </asp:updatepanel> <asp:updateprogress id="updateprogressdata" runat="server" displayafter="500"> <progresstemplate> <div class="loadingpanel"> <asp:image id="loadingimage" runat="server" imageurl="~/images/loading_2.gif" alternatetext="loading ..." tooltip="loading ..." style="padding: 10px;position:fixed;top:45%;left:50%;" /> </div> </progresstemplate> </asp:updateprogress>
and c# code looks this. function displayplot called 2 dropdownlist events , each list passes in 'control'.
private void displayplot(control control) { plotinformation plot = new plotinformation(chartdivid); double range = convert.todouble(rangelist.selectedvalue); string javascript = plot.getplotscript(plotlist.selecteditem.text, range); plotdescription.text = plot.getdataplotdescription(plotlist.selecteditem.text); //string testscript = "<script type=\"text/javascript\">\n\talert('" + plotlist.selecteditem.text + "');\n</script>"; scriptmanager.registerstartupscript(control, control.gettype(), scriptkey, javascript, false); //scriptmanager.registerstartupscript(control, this.gettype(), scriptkey, javascript, false); //if (!clientscript.isstartupscriptregistered(scriptkey)) // clientscript.registerstartupscript(this.gettype(), scriptkey, javascript); }
i know late, spent lot of time on same bug.
try changing:
scriptmanager.registerstartupscript(control, control.gettype(), scriptkey, javascript, false);
to
scriptmanager.registerstartupscript(updatepaneldata, updatepaneldata.gettype(), scriptkey, javascript, false);
Comments
Post a Comment