tags:

views:

122

answers:

1

I have a strange problem with the page I'm designing. I have a link like this:

<a id="asel1" runat="server" href="#"><img id="isel1" runat="server" src="/Images/selbar/1.jpg" /></a>

And when I view source on the resulting page I get this:

<a href="../Cards/#" id="ctl00_ContentMainSection_CardsControl1_asel1"><img src="/Images/selbar/1.jpg" id="ctl00_ContentMainSection_CardsControl1_isel1" /></a>

My goal was to programmatically insert a link if it was applicable to the page in question, and leave a href="#" if it wasn't (basically a blank anchor tag). However now it will take them to an actual link, which of course doesn't exist.

How can I make it stop doing this?

+1  A: 

How are you inserting the link? I've just tried the following:

<a id="asel1" runat="server" href="#">
    <img id="isel1" runat="server" src="/Images/selbar/1.jpg" />
</a>

If you do nothing in the code behind the link is rendered as:

<a href="#" id="ctl00_MainContent_asel1">
    <img src="/Images/selbar/1.jpg" id="ctl00_MainContent_isel1" />
</a>

and if in the Page_Load you define the href:

protected void Page_Load(object sender, EventArgs e)
{
    asel1.HRef = "../Cards";
}

it will render as:

<a href="../Cards" id="ctl00_MainContent_asel1">
    <img src="/Images/selbar/1.jpg" id="ctl00_MainContent_isel1" />
</a> 

which other the id mangling is the expected behavior.

Darin Dimitrov
I neglected to mention that the link is inside a user control; this may have some bearing on its behavior. Even if I have no code-behind and just leave it as href="#" it still wants to change it to href="../Cards/#".
Scott McNair