2013-05-10 19 views
5

我已經搜索了SO &谷歌,但我似乎無法得到這個工作。 該代碼位於我的asp.net應用程序中的「取消」按鈕的代碼隱藏點擊事件中,但似乎沒有關閉彈出窗口。有任何想法嗎?ClientScript.RegisterStartupScript不起作用

try 
{ 
    if (btnCancel.Text == "Close") 
    { 
     String csName1 = "PopupScript"; 
     Type csType = this.GetType(); 

     ClientScriptManager cs = Page.ClientScript; 
     if (!cs.IsClientScriptBlockRegistered(csType, csName1)) 
     { 
      ClientScript.RegisterStartupScript(GetType(), "ClosePopup", "window.close();", true); 
     } 
    } 
} 

更新:回傳後,當我在看的源頁面,我看到相關的唯一代碼:

//<![CDATA[ 
(function() {var fn = function() {$get("ToolkitScriptManager1_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();window.close(); 
document.getElementById('ValidationSummary1').dispose = function() { 
    Array.remove(Page_ValidationSummaries, document.getElementById('ValidationSummary1')); 
} 
+0

是否腳本坐上回發,或者沒有腳本都呈現? – 2013-05-10 14:50:30

+0

@Steven,不知道你的意思 – Csharp 2013-05-10 14:52:37

+0

當你點擊你的取消按鈕,回發發生時,查看頁面的來源。是否輸出'window.close();並且只是不被瀏覽器所接受,或者您發佈的C#代碼存在問題。 – 2013-05-10 14:54:43

回答

0

,因爲我不能讓ClientScript根據需要,我沒有使用下面的代碼要解決此問題的工作:

function closeWin() { 
     //If txt = 'cancel' then close; 
     GetRadWindow().Close(); 
    } 


<td align="center"><asp:Button runat="server" ID="btnClose" Text="Close" 
     OnClientClick="closeWin();return false;" onclick="btnClose_Click"/></td> 
6

你可以用這個來代替

ScriptManager.RegisterStartupScript(this.Page, GetType(), "ClosePopup", "window.close();", true); 

或你也可以試試這個

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ClosePopup", "window.close();", true); 

祝您有美好的一天。

+0

'ScriptManager.RegisterStartupScript'已過時更好ClientScript – David 2016-05-30 14:11:43

+0

使用telerik?替換爲:RadScriptManager.RegisterStartupScript – Alaa 2017-01-31 13:56:09