Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am having a little difficulty in registering the javascript on the client side.

C#
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,"));
      }
      }


However, only function drawVisualisation is rendering but I cannot get the drawVisualisation2 to render to the client-end.
JavaScript
 function drawVisualization(dataValues, chartTitle, columnNames, categoryCaption) {
//do something
}


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


Please advice. Many thanks.
Posted

1 solution

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.
 
Share this answer
 
Comments
miss786 23-May-14 9:53am    
thank you. that helped.
hypermellow 23-May-14 9:54am    
Your welcome, I'm happy it helped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900