Tech Off Post

Single Post Permalink

View Thread: Problem with HTMLAnchor and ASP.Net Cache
  • User profile image
    stevo_

    njapp said:

    A work around is to use the HtmlGenericControl instead of the HtmlAnchor.


                        HtmlGenericControl href = new HtmlGenericControl("a");
                        href.Attributes.Add("href", "http://www.google.com/">http://www.google.com");
                        href.Attributes.Add("title", "Word!");
                        href.InnerText = "Google.com";

    I'm still interested in determining what causes the href to be removed from the control when cached as a HtmlAnchor.

    We've ruled out an overall problem with the AttributeCollection since the Title attribute is cached properly.  Anyone else have an idea?

    I think its a 'bug', the HtmlAnchor control doesn't render the attributes in the usual way, as well as intercepting the href to check if a server side event was attached (in which case it will replace the href), if there isn't a server side event, the href is first resolved (incase the url is an app relative one (ie, ~/foo)), and then the result of that resolution is rendered.. strangely then the resolution code removes the original attribute from the attributes collection..

    This essentually means that a HtmlAnchor that doesn't use a server side event, is a one hit wonder.. once its rendered it .. renders (hurrrr!) itself broken.

    Using a generic control just uses the default attribute rendering and so doesn't suffer this.