c# - 在回发时从服务器端调用 javascript

标签 c# javascript jquery asp.net

var r = {  
        init : function(){  
             r = Raphael("pie");
            //r.g.txtattr.font = "12px 'Fontin Sans', Fontin-Sans, sans-serif";
            r.g.text(320, -330, "Message Status").attr({ "font-size": 20 });

            var pie = r.g.piechart(360, -180, 100,  <%= Session["uStats"] %>, { legend: [<%= Session["vkeyColor"] %>], colors: [<%= Session["vPieColor"] %>]  });
            pie.hover(function () {
                this.sector.stop();
                this.sector.scale(1.1, 1.1, this.cx, this.cy);
                if (this.label) {
                    this.label[0].stop();
                    this.label[0].scale(1.5);
                    this.label[1].attr({ "font-weight": 800 });
                }
            }, function () {
                this.sector.animate({ scale: [1, 1, this.cx, this.cy] }, 500, "bounce");
                if (this.label) {
                    this.label[0].animate({ scale: 1 }, 500, "bounce");
                    this.label[1].attr({ "font-weight": 400 });
                }
            });
            var r = Raphael("pie"),

                    data2 = [<%= Session["vProgressPercentage"] %>];
                    axisx = ["10%", "20%"];
            r.g.txtattr.font = "12px 'Fontin Sans', Fontin-Sans, sans-serif";
             r.g.barchart(80, 25, 100, 320, data2, { stacked: true, colors: [<%= Session["vProgressColor"] %>,'#fff'] });
             axis2 = r.g.axis(94, 325, 280, 0, 100, 10, 1);
        }
        }
          window.onload = function () {
          r.init();
        };

Javascript 在页面加载时执行,我使用更新面板进行部分回发,javascript 在回发期间不执行如何从服务器端调用它。

  <asp:ScriptManager ID="smCharts" runat="server" />
   <script type="text/javascript" language="javascript">
             Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
             Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
             function BeginRequestHandler(sender, args) {
                 r.init();
             }
             function EndRequestHandler(sender, args) {
                 r.init();
             }

            </script>
        <asp:UpdatePanel runat="server" ID="Holder" OnLoad="messsagePercentStats" UpdateMode="Conditional">
            <ContentTemplate>

                <div id="pie" onclick="__doPostBack('Holder', '');" style="top: -125px; left: -20px; width: 610px; position: relative;
                    height: 389px;">
                </div>

这就是我正在尝试的,图表没有改变。它在页面加载时保持不变

protected void Timer_Tick(object sender, EventArgs args)
    {
        String MsgID = HttpContext.Current.Request.QueryString["MsgID"];
        int msgID = Convert.ToInt32(MsgID);
        BindGridViewUsers(msgID);

        ClientScript.RegisterStartupScript(this.GetType(), "loadpie", "r.init();");
        Holder.Update();
        }

最佳答案

使用 ScriptManager.RegisterStartupScript 从更新面板调用 javascript 函数;像这样:

ScriptManager.RegisterStartupScript(this,this.GetType(),"key","javscriptfunction();" , false);

关于c# - 在回发时从服务器端调用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7640180/

相关文章:

javascript - 如何让加载更多数据附加到顶部?

c# - 为什么在这种情况下需要绑定(bind)

javascript - 自定义下拉按钮的辅助功能

javascript - 在 Bootstrap 中以模式打开放大图像

javascript - Bootstrap 4 嵌套选项卡未删除事件选项卡

javascript - jquery 选择图像不起作用

c# - 显式实现的方法具有哪些可访问性?

C# threading with max thread count 然后等待

c# - 如何: Use async methods with LINQ custom extension method

javascript - 如何在 JQuery 中使用 cookie