Documentation on cms:LocalizedHyperlink

Matt Newby asked on February 28, 2014 12:25

A customized widget built for us uses cms:LocalizedHyperlink to create a linked image on our site. However, the image's alt tag is empty, even though the image file it references has Description text in the image library. The custom widget does not have a field for alt text. Looking at the .ascx file, I see

<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_[OurSite]_Global_WidgetBottomCalloutDetailPage" CodeFile="~/CMSWebParts/[OurSite]/Global/WidgetBottomCalloutDetailPage.ascx.cs" %>

<article class="widget02">
    <cms:LocalizedHyperlink ID="hlImage" runat="server"></cms:LocalizedHyperlink>
    <h3>
        <cms:LocalizedHyperlink ID="hlLink" runat="server"></cms:LocalizedHyperlink>
    </h3>
    <p>
        <asp:Literal runat="server" ID="ltrContent"></asp:Literal>
    </p>
</article>

The .cs file associated with this is:

using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CMS.PortalControls;
using CMS.GlobalHelper;
using CMS.CMSHelper;

public partial class CMSWebParts_[OurSite]_Global_WidgetBottomCalloutDetailPage : CMSAbstractWebPart
{
    #region "Properties"

    public string Title
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Title"), "");
        }
        set
        {
            SetValue("Title", value);
        }
    }

    public string Image
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Image"), "");
        }
        set
        {
            SetValue("Image", value);
        }
    }

    public string Content
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Content"), "");
        }
        set
        {
            SetValue("Content", value);
        }
    }

    public string Link
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Link"), "");
        }
        set
        {
            SetValue("Link", value);
        }
    }

    public string LinkTarget
    {
        get
        {
            return ValidationHelper.GetString(GetValue("LinkTarget"), "");
        }
        set
        {
            SetValue("LinkTarget", value);
        }
    }

    #endregion


    #region "Methods"

    /// <summary>
    /// Content loaded event handler
    /// </summary>
    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
    }


    /// <summary>
    /// Initializes the control properties
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            hlImage.Visible = false;
            if (!String.IsNullOrEmpty(Image))
            {
                hlImage.Visible = true;
                hlImage.ImageUrl = Image;
                hlImage.NavigateUrl = Link;
            }

            hlLink.NavigateUrl = Link;
            hlLink.Text = Title;
            hlLink.Target = LinkTarget;

            ltrContent.Text = Content;
        }
    }


    /// <summary>
    /// Reloads the control data
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        SetupControl();
    }

    #endregion
}

I've been searching for any documentation on cms:LocalizedHyperlink, but have not been able to find anything yet. I've been also looking in the various directories on our site for any file that looks like it might contain a LocalizedHyperlink function, but am also coming up empty. How can I pass the image Description into the hlImage's properties so that the LocalizedHyperlink code sticks it in the alt attribute?

-matt

Recent Answers


Brenden Kehren answered on February 28, 2014 19:48

A localized hyperlink is simply an < a > tag or the equivalent of an < asp:Hyperlink > control. There is no ALT attribute to an < a > tag so even if you could, it wouldn't be valid HTML. If you want an alt tag, I'd suggest using an < asp:ImageButton > instead and set the AlternateText property.

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on March 1, 2014 02:36

Hi,

Thank you for your message.

Well <asp:Hyperlink> can set the IMG alt tag when the URL of image is provided. The source for this is the "Text" attribute. I checked the example at w3schools and it seem to work.

The :

<form runat="server">
<asp:HyperLink
ImageUrl="/banners/w6.gif"
NavigateUrl="http://www.w3schools.com"
Text="Visit W3Schools!"
Target="_blank"
runat="server" />
</form>

Becomes:

<form method="post" action="demo_hyperlink.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTc0MDEwNTM2MWRksjlGVMXXEiyUWXmgrY1fEFcdshOUSDLGFtBJefdeVIo=" />
</div>

<a href="http://www.w3schools.com" target="_blank"><img src="/banners/w6.gif" alt="Visit W3Schools!" /></a>
</form>

As you can see the alt tag of the image (not the "a") is being set correctly as it should.

Reference:

link text

Kind regards,

Richard Sustek

0 votesVote for this answer Mark as a Correct answer

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