1

I have a string in my web.config:

<configuration>

    <appSettings>

        <add key="email1" value="mailto:[email protected]" />


    </appSettings>

</configuration>

I want to use that setting in that way (see below):

<p>Write me here: <asp:HyperLink ID="HyperLink503" runat="server" 
        NavigateUrl=<%= ConfigurationManager.AppSettings["email1"] %>>my e-mail</asp:HyperLink>.</p>

However, i get an error. I tried to use a quotes in NavigateUrl, but I get same error. Please, correct my code so it can works.

Thanks in advance !

2
  • 2
    Please post your error Commented Mar 20, 2014 at 14:22
  • GrooV, i have two sections in my web.config with customErrors and httpErrors. Both sections redirect to 404.aspx in case of any errors. I don't know hot to get a speific error code. Commented Mar 20, 2014 at 19:15

2 Answers 2

4

There's a special notation for getting app settings. Also, you had an extra closing bracket.

<asp:HyperLink ID="HyperLink503" runat="server" NavigateUrl='<% $appSettings:email1 %>' Text="my e-mail" />

or

<asp:HyperLink ID="HyperLink503" runat="server" NavigateUrl='<% $appSettings:email1 %>'>my e-mail</asp:HyperLink>
Sign up to request clarification or add additional context in comments.

3 Comments

Great, it works. What if email1 = [email protected] and I want to set a NavigateUrl to mailto:email1 ? How to do concatenation ?
In that case, do something like Yuriy's answer. Put it in the Page_Load function probably. HyperLink503.NavigateUrl = "mailto:" + ConfigurationManager.AppSettings["email1"]; I couldn't figure out how to do it inline with concatenation.
mason, ok. I just will make email2 for that case.
0

Apparently you cannot use <% ... %> in server-side controls. As an alternative I suggest setting the value in code behind (e.g. in page load event):

HyperLink503.NavigateUrl = ConfigurationManager.AppSettings["email1"];

2 Comments

You can use <% ... %> in server controls, although your way works too.
Yup. Nice one about $appSettings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.