如何在客户端呈现功能? [英] How to render function on the client-side?

查看:88
本文介绍了如何在客户端呈现功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端注册javascript时遇到一些困难。



I am having a little difficulty in registering the javascript on the client side.

protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {

          JavaScriptSerializer jss = new JavaScriptSerializer();
          ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
              //string.Format("<script type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
         string.Format("<script type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
          jss.Serialize(GetData()),
      "Name Example",
      "Name",
      "Type Example",
       "Type,"));

          }

      if (!IsPostBack)
      {
          JavaScriptSerializer jss = new JavaScriptSerializer();
          ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
              //string.Format("<script type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
         string.Format("<script type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){{drawVisualization2({0},'{1}','{2}','{3}');}});</script>",
          jss.Serialize(GetData2()),
      "Name Example",
      "Name",
      "Type Example",
       "Type,"));
      }
      }





但是,只有函数drawVisualisation正在渲染但我无法获得drawVisualisation2呈现给客户端。



However, only function drawVisualisation is rendering but I cannot get the drawVisualisation2 to render to the client-end.

 function drawVisualization(dataValues, chartTitle, columnNames, categoryCaption) {
//do something
}


function drawVisualization2(dataValues, chartTitle, columnNames, categoryCaption) {
//do something
}





请咨询。非常感谢。



Please advice. Many thanks.

推荐答案

问题似乎是对ClientScript的调用中的 key 参数.RegisterStartupScript



您正在为两个调用使用值TestInitPageScript。如果你将第二次调用更改为其他内容,那么它将注册两个块。



...希望它有所帮助。
The problem appears to be the key parameter in your calls to ClientScript.RegisterStartupScript

You are using the value "TestInitPageScript" for both calls. If you change the 2nd call to something else, then it will register both blocks.

... Hope it helps.


这篇关于如何在客户端呈现功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆