2011-10-03 35 views
5
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 được thực thi khi tải trang, tôi thực hiện một phần postback bằng bảng cập nhật, javascript không được thực hiện trong khi đăng lại cách gọi từ phía máy chủ.Gọi javascript từ phía máy chủ trên postback

<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> 

Đây là những gì tôi đang cố gắng và biểu đồ không thay đổi. nó vẫn không đổi như khi tải trang

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(); 
     } 

Trả lời

5

Sử dụng ScriptManager.RegisterStartupScript để gọi hàm javascript từ bảng cập nhật; một cái gì đó như thế này:

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

window.onload không hoạt động sau khi trang đã được tải. Sử dụng

$(function(){ r.init();})

thay thế.

2

Bạn có thể đưa kịch bản này bên trong một hàm:

function foo() { 
    ... 
} 

đó sẽ được thực hiện khi DOM tải:

window.onload = function() { 
    foo(); 
}; 

và khi phía máy chủ postback từ một UpdatePanel:

ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo();", true); 
+0

Tôi đã cập nhật mã, bạn có thể nói cho tôi biết tôi đang đi sai không – Mark

0

Bạn cũng có thể làm

Response.Write("<script language='javascript'>alert('I'm an alert');</script>"); 

Chỉ cần đặt mã của bạn trong thay vì alert. Bạn có thể gọi hàm từ đó, nhưng tôi chưa thử nghiệm.

Các vấn đề liên quan