Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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



Below is how I wana call in code-behind:

C#
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.

-Regards
Anurag
Posted

1 solution

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 http://www.w3schools.com/xml/xml_syntax.asp[^] 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.
 
Share this answer
 
v2
Comments
Anurag Sinha V 27-Mar-13 9:31am    
Thanks ryanb31..will try it out and will keep the thread updated...

-Anurag
Anurag Sinha V 28-Mar-13 3:32am    
Hi ryanb31....you 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...

_Anurag

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900