How can I stop ASP.Net from encoding anchor tags in List Items when the page renders?
I have a collection of objects. Each object has a link property. I did a foreach and tried to output the links in a BulletedList, but ASP encoded all the links.
Any idea? Thanks!
Here's the offending snippet of code. When the user picks a specialty, I use the SelectedIndexChange event to clear and add links to the BulletedList:
if (SpecialtyList.SelectedIndex > 0)
{
PhysicianLinks.Items.Clear();
foreach (Physician doc in docs)
{
if (doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));
}
}
}
Give us an example... the object's exact type/value and what is being rendered to HTML.
If you're talking about ASP.NET changing
&
to&amp;
... you can sometimes get around this sort of thing by using the ASCII code version instead of the HTML shortcut:&
You can replace the Bulletedlist with a repeater
Instead of
PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));
, add doc.Link to a List Object and use it to bind the repeater. You can include any html you want in the repeater itemtemplateSomething like
And In ASPX