Prevent ASP.NET from Outputting Coding Strings

How can I stop ASP.Net from encoding anchor tags on list items when the page renders?

I have a collection of objects. Every object has a link property. I did a foreach and tried to output links to BulletedList, but ASP encoded all links.

Any idea? Thanks!

Here's an offensive code snippet. When the user selects a specialty, I use the SelectedIndexChange event to clear and add references 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>"));    
            }
        }
    }

      

+2


a source to share


2 answers


You can replace Bulletedlist with a repeater

Instead PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));

add doc.Link to the list object and use it to link the relay. You can include any html you want in the itemtemplate repertoire

Sort of



List<string> docLinks=new List<string>();
    if (SpecialtyList.SelectedIndex > 0)
        {


            foreach (Physician doc in docs)
            {
                if (doc.Specialties.Contains(SpecialtyList.SelectedValue))
                {
                  docLinks.add(doc.Link) ;
               }
            }
            Repeater1.DataSource=docLinks;
            Repeater1.DataBind();
        }

      

And in ASPX

<ul>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
            <li><a href="<%# Container.DataItem.ToString()%>"><%# Container.DataItem.ToString()%></a></li>
            </ItemTemplate>
        </asp:Repeater>
</ul>

      

+6


a source


Give an example ... the exact type / value of the object and what is displayed in the HTML.



If you're talking about changing ASP.NET from &amp;

to &amp;amp;

... sometimes you can get around this thing by using the ASCII version of the code instead of the HTML shortcut:&#38;

0


a source







All Articles