[英]ConfigurationManager.AppSettings is working in <title> but not for <asp:Label>
我從 web.config 獲得<title>
和<asp:Label>
的價值。
在<title>
的情況下,它由ConfigurationManager.AppSettings["Key"]
工作。
如果是<asp:Label>
,它由AppSettings: Key
工作。
是否可以管理代碼並使用ConfigurationManager.AppSettings["Key"]
或AppSettings: Key
?
例如:僅使用ConfigurationManager.AppSettings["Key"]
。
web.config
<configuration>
<appSettings>
<add key="Title" value="My Title"/>
</appSettings>
</configuration>
.aspx
<head runat="server">
<%--It's working--%>
<title><%: ConfigurationManager.AppSettings["Title"] %></title>
<%--It's not working--%>
<%--Compiler Error Message: CS0103: The name 'Title' does not exist in the current context--%>
<%--<title><%: AppSettings: Title %></title>--%>
</head>
<body>
<%--It's not working--%>
<%--Parser Error Message: Server tags cannot contain <% ... %> constructs.--%>
<%--<asp:Label ID="label1" Text="<%: ConfigurationManager.AppSettings["Title"] %>" runat="server" />--%>
<%--It's working--%>
<asp:Label ID="label1" Text="<%$ AppSettings: Title %>" runat="server" />
</body>
<appSettings>
<add key ="Name" value ="Name"/>
</appSettings>
<asp:Label ID="lbl" runat="server" Text="<%$appSettings:Name %>"></asp:Label>
<asp:TextBox ID = "txtBox1" runat = "server" Text = "<%$appSettings:Name %>" />
<span><%=System.Configuration.ConfigurationManager.AppSettings["Name"]%></span>
這是實現的最簡單方法...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.