我正在尝试在我的母版页中使用 AppSettings 显示 asp:ImageButton 的 ImageUrl,如下所示:
View.Master:
....
<asp:ImageButton ID="aspShowHideButton" ImageUrl='<%# System.Configuration.ConfigurationManager.AppSettings("HomeDirectory").ToString()%>images/arrowUpButton.gif' runat="server" />
不幸的是,当我在浏览器中提取它时,这是正在呈现的代码:
<input type="image" name="ctl00$ctl00$aspContentMain$aspShowHideButton" id="aspContentMain_aspShowHideButton" onmouseover="ShowHideButtonMouseOver()" onmouseout="ShowHideButtonMouseOut()" src="../%3C%25#%20System.Configuration.ConfigurationManager.AppSettings(%22HomeDirectory%22).ToString()%25%3Eimages/arrowUpButton.gif" />
因此,它从字面上获取了我的 ImageUrl,但我希望它获取键的值,即:
...
<appSettings>
....
<add key="HomeDirectory" value="/" />
....
我试过了,删除了“ToString()”函数,我试过 System.Configuration.... 语句前面的“#”和“$”。我还尝试尝试让它在 Page_Load 函数中工作,使用:
Protected Sub Page_Load(....)
If Not IsNothing(Master.FindControl("aspShowHideButton")) Then
Dim ShowHideButton As ImageButton = Master.FindControl("aspShowHideButton")
ShowHideButton.ImageUrl = System.Configuration.ConfigurationManager.AppSettings("HomeDirectory") + "images/arrowUpButton.gif"
End If
但这似乎也不起作用,我假设是因为它找不到我正在寻找的控件(即 aspShowHideButton)。
从根本上说,我希望在我的 web.config 文件中有一个键/值对,它允许我更改图像的位置,并且我希望能够在我的母版页上的 ImageButton:ImageUrl 中使用这个键/值对,这似乎是一件非常受欢迎的事情。任何建议,方向,不胜感激!
谢谢!