0

我在后面的代码中使用 Response.Write 在客户端中运行 javascript,它在RowCommandgridview 事件中触发:

protected void RowCommand(object sender, GridViewCommandEventArgs e)
{
    var index = int.Parse(e.CommandArgument.ToString());
    var val = gvwCus.DataKeys[index][0].ToString();
    PopupWindow("../Main/Detail.aspx?idc=" + val,900.ToString(),600.ToString());
}
private void PopupWindow(string query, string width, string height)
{
    var re = "<script language=\"javascript\">var left=(screen.width/2)-(" + width +"/2); var top=(screen.height/2)-(" + height + "/2); window.open(" + query +",'PopUp','toolbar=no, location=0, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ",top=' + top + ',left=' + left);</script>";
    Response.Write(re);
}

我在客户端编写了相同的代码,它运行正常,但在后面的代码中,它不起作用。

4

2 回答 2

1

query您在编写脚本时没有用引号括起来。

... window.open('" + query +"','PopUp', ...
于 2013-06-19T02:29:40.553 回答
0

而不是响应只是使用 .RegisterStartupScript

    string script="var left=(screen.width/2)-(" + width +"/2); var top=(screen.height/2)-(" +
 height + "/2); window.open(" + query +",'PopUp','toolbar=no, location=0, directories=no,
 status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + width + ",
 height=" + height + ",top=' + top + ',left=' + left);"

ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "script", true);
于 2013-06-19T02:31:09.910 回答