2010-08-02 43 views

回答

8

您可以在頁面的標記使用下面的代碼:

<script language="JavaScript" type="text/javascript"> 
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>'; 
</script> 
1

使用以下命令:

var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"]; 

您可能會發現,它的工作,你需要添加一個引用到System.Configuration.dll,如果你不已經有一個。

創建一個新的頁面,並在Page_Load中放線,使這一切寫着:

Response.Clear(); 
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"]; 
Response.Write(value); 
Response.End(); 

您現在可以從Javascript使一個AJAX調用的頁面,也許using ExtJs和文本將返回你的JavaScript。

或者,你可以把下面的到你的頁面:

<script language="javascript" type="text/javascript"> 
    var appSettingValue = '<%=System.Configuration.ConfigurationManager.AppSettings["imagetype"]%>'; 

    // The variable "appSettingValue" will contain the string from your web.config 
    alert(appSettingValue); 
</script> 
+1

這是MVC ... ...有沒有...的Page_Load – 2010-08-02 14:29:07

+0

@ŁukaszW.pl,是的,但一般的要點是一樣的。出於某種原因,我的眼睛在「asp.net」之後停止閱讀 - 今天是漫長的一天! =) – Rob 2010-08-02 14:35:10