2

我有这个功能:

 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);
}

如您所见,我有一个变量 nid 根据单击的树节点获得不同的值为 1、2、3。
我可以将该nid变量值作为参数直接传递给javascript函数作为show(nid)吗?
如果不是我该怎么办?

我的javascript函数如下:

function show(nid) 
{

    if (nid == 4) {
        alert('testing');
    }
    else
     {
         alert('what???');
     }
}
4

2 回答 2

4
//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); 
于 2014-07-01T08:46:18.400 回答
3

尝试连接:

ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", "show(" + nid + ")", true);
于 2014-07-01T08:46:49.163 回答