문제

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.

도움이 되었습니까?

해결책

You did not wrap query in quotes when composing the script.

... window.open('" + query +"','PopUp', ...

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top