Prepopulate alt tag when using "Insert media" toolbar button

Gustavo Quevedo asked on September 21, 2020 19:50


I'm currently working on a Kentico 12 SP MVC site where editors can add images from the media library into a long-text property (Rich Text editor).

Is there any solution to get the alt tag prepopulated with the image title or description from the media library when using the "Insert image/media" button in the toolbar?

It seems to add the alt tag always empty and I can't even find a way to enter it within a dialog, apart from manually editing the source code.

Any help would be appreciated.

Kind regards,


Correct Answer

Gustavo Quevedo answered on October 1, 2020 16:53


I finally contacted Kentico support who helped with a source code customisation valid for this scenario.

In the CMSApp solution I've had to edit the file \CMSModules\Content\Controls\Dialogs\Properties\HTMLMediaProperties.ascx.cs

There is the Validate() method where you can add the below within the MediaTypeEnum.Image case:

if (string.IsNullOrEmpty(txtAlt.Text))
   txtAlt.Text = GetAltText(OriginalUrl);

You can add the following code e.g. on the line 1272, right before errorMessage = errorMessage.Trim();

Please note that you would need to implement that GetAltText() method that retrieves the MediaFileInfo object by using MediaFileInfoProvider.GetMediaFileInfo()



0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.