views:

241

answers:

2

I am trying to use the <%$ AppSettings: .. %> shortcut in an asp.net user control.

I am able to use the syntax fine when binding a property to an appsetting, however I want to use an appsetting to hold a page id. for exmaple:

<a href="default.aspx?page=<%$ AppSettings:TestPageID %>">Test link</a>

This method does not work, so my question is, can the appsetting shortcut be used like this to insert a literal, or can anybody suggest a way I can achieve this.

Many thanks,

Adam

A: 

Try:

<%= System.Configuration.ConfigurationSettings.AppSettings.Get("TestPageID") %>
jlech
Kinda defeats the purpose of it being a shortcut. Would be better to add the reference and add it to the uses then just call AppSettings.Get("TestPageID")
James
Thanks jlech, that does work, however this is something that I would like to pass over to our designers so it would be nice to have a single way of accessing the appSettings or some minor variation of "AppSettings:"
Adam Jenkin
@James - very true, just wanted to give the fully qualified name.@Adam - James method to shorten the name should work as well. Another thing you can try is to make the hyperlink a server control (i.e. <asp:hyperlink runat="server"></asp:hyperlink>) in the C# backend script of the page, just write a simple IF statement to check the value of "TestPageID" and set it to the hyperlink's NavigateURL property.
jlech
+1  A: 

add literal into the anchor tag.

<a href="/default.aspx?page=<asp:Literal runat="server" Text="<%$ appSettings:TestPageId %>"/>">Test Link</a>
tentonipete
perfect!.. thanks tentoni!
Adam Jenkin