0

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

<div class="jgauge" ></div>

$(document).ready(function () {  
    var ctl; 
    ctl = new jGauge();   
    ctl.init();
)}

Let's say I need to pass few parameters to init. like... ctl.init(a, b); from code behind, how can I achieve that? I tried something like this...

string script2 = String.Format("init('{0}','{1}')", param1, param2);

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "initialize control", script2, true);

But it's not working. I got:

ReferenceError: init is not defined

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

your script would be like:

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

and in code behind have two public strings

public string param1 = string.Empty;
public string 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.