If you're willing to add the runat="server"
attribute to your img tags, then in your code behind you can loop through the list of controls on your page and for all the img
tags, update the alt
attribute. I wrote this without testing so there may be some minor tweaks required.
private void UpdateImgTags<T>(ControlCollection controlCollection)
where T : Control
{
foreach (Control control in controlCollection)
{
if (control is T) {
string filename = (T)control.Attributes["src"];
filename = IO.Path.GetFileName(filename);
(T)control.Attributes.Add("alt",filename);
}
}
}
To call the method:
UpdateImgTags<HtmlImage>(Page.Controls)