2011-09-28 64 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); 注:我已經改變了\」爲「