2011-09-28 63 views
0

我的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无法正常工作。

+1

为什么这是标记[标签:java],而不是[标签:c#]? –

+0

我猜java脚本代码有问题.. –

+0

你能显示生成的HTML? –

回答

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(); 
    } 
} 
+0

不工作... –

+1

究竟发生了什么?它有什么作用吗?你有任何错误? –

+0

为了安全起见,你可以在这里添加一个分号:'newwindow.focus();' –

0

这个问题会很容易回答,如果你能提供生成的HTML。要查找生成的HTML,请在浏览器窗口中查看呈现的页面并执行查看源代码。见How do I check my site's source code

与您所提供的所有建议,我可以让已经通过@詹姆斯约翰逊代码 请参阅轻微修正詹姆斯码 btnReplay.OnClientClick = String.Format("poptastic('Configuration.aspx?id={0}');return false;", e.CommandArgument); 注:我已经改变了\”为“