ASP.NET HyperLink - Image Alt Tag Customization

How to set alt tag for image that was set with HyperLink.ImageUrl? I read an article that says you should be able to do HyperLink.Attributes["text"] = "My Alt Text", but that doesn't work.

I want to try to avoid creating a separate image control and add it to this hyperlink just to set the Alt tag.

Thank.

+3
source share
3 answers

it can work with attributes, as you mentioned, but you must set such an attribute in the PreRender event on the page or in HyperLink, if you set it before PreRender, you will most likely lose it.

+1
source

asp: "". , alt , ImageUrl.

ETA: Andrew MacNeill , .

:

hyperLink.Text = "My Alt Text"; 
hyperLink.NaviateURL = "www.myurl.com";
hyperLink.ImageURL = "myimage.jpg";

Renders HTML :

<a href="www.myurl.com">
    <img src="myimage.jpg" title="My Alt text" alt="My Alt Text">
    </img>
</a>
+9

From codebehind you can use something like this:

HyperLink HyperLink1 = (HyperLink)e.Row.FindControl("HyperLink1");
HyperLink1.ImageUrl = "Images\\Success.png";
HyperLink1.ToolTip = "Completed";

The ToolTip property will display alternative text for the image.

-2
source

Source: https://habr.com/ru/post/1791956/


All Articles