Click here to Skip to main content
14,336,087 members
Rate this:
Please Sign up or sign in to vote.
Hi people,

I am having a strange problem.
I want to have a add tag containing an img tag under appSettings section in web.config file, so that in my code-behind I can call Server.MapMethod method and make use of it.
The code builds successfully but it shows a sort of error as:

The element appSettings has invalid child elements.Only allowed elements are add, remove,clear.

Below is my web.config section:

<add key="Third" value="<img src="Images/Pic.png"  önclick="Redirect('');" style="margin-removed250px; removed:pointer;" />"/>
<add key="Section1" value="You don't have access..."/>

Below is how I wana call in code-behind:

Section1.Text = Server.MapPath(ConfigurationManager.AppSettings["Section1"]);
Third.InnerHtml = Server.MapPath(ConfigurationManager.AppSettings["Third"]);

I tried putting lt; and gt; stuffs and for < and > signs, but it doesn't work.
Any ideas mentors??Help will be highly appreciated.


1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You do need to encode it, because it is XML. So, the value will be "&lt;img src=&quot;Images/ etc.

You can refer to[^] for special characters.

I would recommend putting it into a settings table in the database and possibly even breaking up your onclick into a different field. Your trying to cram a lot into an xml value, but it should work if you get the syntax right.
Anurag Sinha V 27-Mar-13 9:31am
Thanks ryanb31..will try it out and will keep the thread updated...

Anurag Sinha V 28-Mar-13 3:32am
Hi suggestion works..we actually need to encode the quotation marks since its in the form of an XML...
And I am doing this coz this is a client requirement...had done these stuffs via other means too but the client wants these things to be included in the configuration file..hence the drill...


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100