Application Links Settings from usercontrols

In my usercontrol.ascx, I am trying to dynamically generate links using the value I stored in the web.config.

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

      

and when i try to run i get parser error

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

      

I know that I probably missed something relatively minor.

+1


a source to share


5 answers


    <a href="<%= System.Configuration.ConfigurationManager.appSettings("MYPATH") %> "> link </a>


should work (at least on the IIS server I'm using). (Unfortunately, it's more verbose)

+2


a source


<%= ConfigurationManager.AppSettings["myKey"] %>

      



EDIT: don't forget =

+4


a source


Try this instead

.ascx

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

      

in the code behind

Literal1.Text = "<a href='" + appSettings.MYPATH + "'/file.aspx">link</a>"

      

+1


a source


A more accurate answer would be as follows:

<a href="<%= System.Configuration.ConfigurationManager.AppSettings["param_name"] %>">Link</a>

      

0


a source


Use a colon instead of a period and add runat="server"

:

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

      

The documentation is n't very clear, but ASP.Net expressions are meant to be used in server tags. Thus, if you want to use it in a normal html tag, you must add runat="server"

so that the tag is processed on the server where the expression will be evaluated.

0


a source







All Articles