Asp.net 使用AppSettings键设置母版页上ImageButton中的ImageUrl

Asp.net 使用AppSettings键设置母版页上ImageButton中的ImageUrl,asp.net,master-pages,imagebutton,Asp.net,Master Pages,Imagebutton,我正在尝试使用母版页中的AppSettings显示asp:ImageButton的ImageUrl,如下所示: View.Master: .... <asp:ImageButton ID="aspShowHideButton" ImageUrl='<%# System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString()%>images/arrowUpButton.gif' r

我正在尝试使用母版页中的AppSettings显示asp:ImageButton的ImageUrl,如下所示:

 View.Master:
 ....
 <asp:ImageButton ID="aspShowHideButton" ImageUrl='<%# System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString()%>images/arrowUpButton.gif' runat="server" />
但这似乎也不起作用,我假设是因为它找不到我想要的控件(例如aspShowHideButton)

基本上,我希望在我的web.config文件中有一个键/值对,允许我更改图像的位置,并且我希望能够在母版页上的ImageButton:ImageUrl中使用这个键/值对,这似乎是一个非常流行的做法。任何建议、指导,我们都将不胜感激


谢谢

要在服务器标记中使用appsettings,请使用以下语法:

<%$ AppSettings:HomeDirectory %>
现在,如果您确实需要直接在ImageButton标记中定义这种连接,则需要使用代码表达式生成器

使用代码表达式生成器,您将能够在ImageButton标记中使用这种语法:

ImageUrl="<%$ Code: System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString() + "images/arrowUpButton.gif" %>"
ImageUrl=“”

要在服务器标记中使用appsettings,请使用以下语法:

<%$ AppSettings:HomeDirectory %>
现在,如果您确实需要直接在ImageButton标记中定义这种连接,则需要使用代码表达式生成器

使用代码表达式生成器,您将能够在ImageButton标记中使用这种语法:

ImageUrl="<%$ Code: System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString() + "images/arrowUpButton.gif" %>"
ImageUrl=“”
您可以尝试以下方法:

<asp:ImageButton runat="server" ImageUrl="<%$ AppSettings:FullPath %>images/image001.jpg" ></asp:ImageButton>
您可以尝试以下方法:

<asp:ImageButton runat="server" ImageUrl="<%$ AppSettings:FullPath %>images/image001.jpg" ></asp:ImageButton>

@daniloquio更新了另一种可能性。@daniloquio更新了另一种可能性。您的编辑无效,因为OP希望在appsettings中有HomeDirectory,而不是完整路径。很明显,OP可能会将appsettings[“homeDir”]与sufix连接在一起,从而在页面上设置ImageUrl。您的编辑无法工作,因为OP希望appsettings中包含HomeDirectory,而不是完整路径。显然,OP可以在页面上设置ImageUrl,并将appsettings[“homeDir”]和sufix连接起来。
ImageUrl="<%$ Code: System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString() + "images/arrowUpButton.gif" %>"
<asp:ImageButton runat="server" ImageUrl="<%$ AppSettings:FullPath %>images/image001.jpg" ></asp:ImageButton>
<appSettings> 
<add key="testKey" value="images/up.gif" />
</appSettings>  
<asp:ImageButton ID="ImageButton1" runat="server" />
 protected void Page_Load(object sender, EventArgs e)
    {
        this.ImageButton1.ImageUrl = ConfigurationManager.AppSettings["testKey"];
    }