November Happy Hour will be moved to Thursday December 5th.

AltText is not displayed in Image (Web forms)

Vote:
 

Here is my ImageMedia.cs file which inherits ImageData

public class ImageMedia : ImageData
{
public virtual string AltText { get; set; }
public virtual string TitleText { get; set; }
}

And it is displaying in the editmode as follows,

I have made a ContentReference as like below in the block

[CultureSpecific]
        [Required]
        [UIHint(UIHint.Image)]
        [Display(
            Name = "Image",
            GroupName = SystemTabNames.Content,
            Order = 40)]
        public virtual ContentReference Image { get; set; }

However, when I used to show that in the view (Web Forms), it is just displaying the image. Without having any Alt text or Title.

I have accessed that image like below in the view,

<EPiServer:Property runat="server" PropertyName="Image" CssClass="imageCls"></EPiServer:Property>

When it is rendered in view, the code looks like this,

<img title="true" class="imageCls" src="/globalassets/elephant.jpg" style="border-width:0px;">

How can I show the AltText and the TitleText as "alt" and "title" in the finally rendered view?

Thanks in advance :)

I am having,
EPiServer.CMS.Core version=11.11.0
EPiServer.CMS.UI version=11.14.0
EPiServer.CMS.UI.Core version=11.14.0

#201145
Feb 07, 2019 5:52
Vote:
 

Here are a couple of approaches at rendering image URLs which you could use for inspiration:

<asp:Image runat="server" ImageUrl="<%=UrlResolver.Current.GetUrl(CurrentPage.ImagePropertyName)%>"/>
<img src="<%=UrlResolver.Current.GetUrl(CurrentPage.ImagePropertyName)"/>

Just render the appropriate attributes by accessesing the properties of the block in the same way as above.

Urrgh, web forms...

#201146
Feb 07, 2019 7:42
Vote:
 

Thanks,

Is there a way to access the ImageMedia attributes (AltText and TitleText) by using the ContentReference?

I have tried to add the page property as below,

[CultureSpecific]
        [Required]
        [UIHint(UIHint.Image)]
        [Display(
            Name = "Image",
            GroupName = SystemTabNames.Content,
            Order = 40)]
        public virtual ImageMedia Image { get; set; }

But it throws an error in runtime saying "Type 'ImageMedia' could not be mapped to a PropertyDefinitionType"

#201148
Edited, Feb 07, 2019 8:33
Vote:
 

Ok gotcha !,

I have used

var img = contentLoader.Get<ImageMedia>(CurrentBlock.Image);

to get the ImageMedia object from the codebehind. Now I could access the inner attributes from it.


Thanks :)

#201153
Edited, Feb 07, 2019 9:25
Vote:
 

No worries :)

Please mark as answer, although I hope nobody else is actively developing on webforms!

#201154
Feb 07, 2019 9:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.