- 堆棧內存溢出
  簡體   English   中英

ConfigurationManager.AppSettings 正在工作<title>但不是為了</title><asp:label></asp:label>

[英]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>

Output ConfigurationManager.AppSettings 在 <title> 中工作,但不適用於 <asp:Label>

    <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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM