I have a custom anchor create function
public static Anchor Create(string name, object variant)
{
return new Anchor(string.Format("{0}{1}", (name.StartsWith("#") ? name : string.Format("#{0}", name)), variant).Replace(' ', '_'));
}
public static Anchor Create(string name)
{
return Create(name, string.Empty);
}
Which creates the anchor tags on the webpage. The following is the call on the .ascx control
<asp:DataList ID="_meterLinkBar" runat="server" RepeatDirection="Horizontal" CssClass="bodytext4" RepeatLayout="Flow">
<ItemTemplate>
<a href='<%# Anchor.Create("Meter", Container.ItemIndex + 1) %>' title='<%# Eval("Name", "{0} measurement results") %>'>
<%# FormatMeterName(Eval("Name") as string, Container.ItemIndex) %></a>
</ItemTemplate>
<SeparatorTemplate>|</SeparatorTemplate>
<FooterTemplate>
<hr style="height: 1px; border-width: 0; color: #006690; background-color: #006690;" />
</FooterTemplate>
</asp:DataList>
The following is the actual item with the anchor tag
<ItemTemplate>
<a id='<%# Anchor.Create("Meter", Container.ItemIndex + 1) %>'></a>
....
</ItemTemplate>
EDIT
Here is the toString method
public override string ToString()
{
return _name;
}
The following is the constructor
private Anchor(string name)
{
_name = name;
}
Now everything works in IE, but in the other browsers, the links are rendered properly but the actual anchor tag itself shows as ##whatever
Any suggestions?
Ideally, we probably need to see the HTML produced as well. It sounds like you are getting two #
href="##name". If that is the case, then the Anchor’s .toString() method probably also adds the # before the name of the anchor. So, in that case, if it works in IE, it’s because IE ignores the repetition while other browsers do not ignore it.Check the .toString() method and see what’s in it. If it’s also adding the #, then you’d need to change your code like so:
EDIT
Ah, I’m silly. I just realized, you are putting this in the “ID” of the
<a>tag. You do NOT put # into the ID. You only put that into thehref="#Meter", e.g.If your id=’#Meter’, then that would cause problems.