2

I have this function:

 protected void mytv_SelectedNodeChanged(object sender, EventArgs e)
 {
    TreeView tv = sender as TreeView;
    var nid = tv.SelectedNode.Value;
    ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", "show(nid)", true);
}

As you can see, I have a variable nid that gets different value as 1,2,3 according to the treenode clicked.
Can i pass that nid variable value directly as a parameter to the javascript function as show(nid)?
If not what do i do?

My javascript function is as follows:

function show(nid) 
{

    if (nid == 4) {
        alert('testing');
    }
    else
     {
         alert('what???');
     }
}
user35
  • 468
  • 1
  • 9
  • 24

2 Answers2

3
//for string value
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", string.Format("show('{0}')", nid), true);
//for int value
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", string.Format("show({0})", nid), true); 
Robert Fricke
  • 3,637
  • 21
  • 34
3

try concatenating :

ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", "show(" + nid + ")", true);
Zaki
  • 5,540
  • 7
  • 54
  • 91