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

ご覧のとおり、クリックされたツリーノードに応じて 1、2、3 のように異なる値を取得する変数 nid があります。
その 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 に答える