2012-12-11 15 views
4

我試圖存儲在配置文件中的URL,但是當我從文件獲得一個URL從web.config中

下面檢索URL它不工作是我的代碼

在網頁。配置,我有

<add key="URL" value="/NG/Viewer/ViewerSummary.aspx"/> 

在我的aspx.cs頁面,我有以下的代碼

string url = ConfigurationManager.AppSettings["URL"]; 

string strScript = "window.open(url?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');"; 
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true); 

風如果我編寫上面的代碼,ow不會打開,但如果我在下面的代碼中執行此操作,窗口將打開。

string strScript = "window.open('/NG/Viewer/ViewerSummary.aspx?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');"; 
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true); 

如何通過將值放入配置文件來打開窗口?
任何幫助表示讚賞。

謝謝。

回答

6

這可能是因爲你粘貼的代碼有幾個錯誤。第一個錯誤是你錯過了window.open調用中的單引號。另一個錯誤是您實際上沒有使用url變量。

試試這個:

string strScript = "window.open('" + url + "?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');"; 
0
string strScript = "window.open('" + url + "?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');"; 
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);