You did not wrap query
in quotes when composing the script.
... window.open('" + query +"','PopUp', ...
Question
I used Response.Write in code behind to run javascript in client like that,it fired in a RowCommand
event of gridview:
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);
}
I wrote a same code in client, it run okay, but in code behind, it doesn't work.
La solution
You did not wrap query
in quotes when composing the script.
... window.open('" + query +"','PopUp', ...
Autres conseils
instead of response just use .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);