将querystring变量发送到新的弹出窗口

时间:2011-09-28 14:30:45

标签: c# javascript asp.net

我的JavaScript代码是:

var newwindow;
    function poptastic(url) {
     newwindow = window.open(url, 'name', 'height=400,width=200');
    if (window.focus) { newwindow.focus() }
    }

我的C#代码:

 foreach (GridViewRow row in GvComments.Rows)
            {
                Button btnReplay = (Button)row.FindControl("btnReplay");
                string url = "javascript:poptastic('Configuration.aspx?id=" + e.CommandArgument + "')";
                btnReplay.Attributes.Add("onclick", url);
            }

我认为C#代码存在问题,因为当我在标记中使用此JavaScript代码时,它可以正常工作,但attribute.add无效。

2 个答案:

答案 0 :(得分:0)

请尝试使用OnClientClick代替:

btnReplay.OnClientClick = String.Format("poptastic(\"Configuration.aspx?id={0}\");return false;", e.CommandArgument);

修改

这是一个可以用来打开弹出窗口的JavaScript函数:

openChildWindowWithDimensions = function(url, width, height, showMenu, canResize, showScrollbars) {
    var childWindow = window.open(url, "", "\"width=" + width + ",height=" + height + ",menubar=" + (showMenu ? "1" : "0") + ",scrollbars=" + (showScrollbars ? "1" : "0") + ",resizable=" + (canResize ? "1" : "0") + "\"");
    if (childWindow){
        childWindow.resizeTo(width, height);
        childWindow.focus();
    }
}

答案 1 :(得分:0)

如果您可以提供生成的HTML,则此问题很容易回答。要查找生成的HTML,请转到您正在查看呈现页面的浏览器窗口并执行查看源。见How do I check my site's source code

使用您提供的代码我可以提出的所有建议都是由@James Johnson制作的 请参阅James代码的一个小修正     btnReplay.OnClientClick = String.Format("poptastic('Configuration.aspx?id={0}');return false;", e.CommandArgument); 注意:我已将“更改为”