Skip to content Skip to sidebar Skip to footer

How To Call This Javascript Function From Code Behind

I'm putting javascript created controls (http://www.dariancabot.com/projects/jgauge_wip/) on my page.
$(document).ready(function () {

Solution 1:

The init is a method inside jGauge instance. So you must instantiate before you call those mathode. Try bellow:

string script2 = String.Format("var ctl; ctl = new jGauge();  ctl.init('{0}','{1}');", param1, param2);
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "initialize control", script2, true);

Solution 2:

one more way of doing it is to have public variables,

your script would be like:

$(document).ready(function () {  
    var ctl; 
    ctl = newjGauge();   
    ctl.init(<%=param1 %>, <%=param2 %>);
)}

and in code behind have two public strings

publicstring param1 = string.Empty;
publicstring param2 = string.Empty;

on your page_load or any other event, you can set value of these 2 variables normally, like:

param1 = "100";

rest of the code will work as it is.

Post a Comment for "How To Call This Javascript Function From Code Behind"