views:

330

answers:

3

In my .ascx usercontrol i'm trying to dynamically generate links using a value i've stored in web.config.

<a href="<%$appSettings.MYPATH%>/file.aspx">link</a>

and when i try running, i get a parser error

Literal expressions like '<%$appSettings.MYPATH %>' are not allowed. Use <asp:Literal runat="server" Text="<%$appSettings.MYPATH%>" /> instead.

I know i'm probably missing something relatively minor.

+1  A: 

Try this instead

.ascx

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

in code behind

Literal1.Text = "<a href='" + appSettings.MYPATH + "'/file.aspx">link</a>"
Vikram
+4  A: 
<%= ConfigurationManager.AppSettings["myKey"] %>

EDIT:Don't forget the =

Wayne Hartman
+2  A: 
    <a href="<%= System.Configuration.ConfigurationManager.appSettings("MYPATH") %>">link</a>

should work (it at least does on the IIS server I use). (Unfortunately it's more verbose)

Thr4wn