+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom SitefinityHyperLink Control

Custom SitefinityHyperLink Control

5 posts, 0 answered
  1. John
    John avatar
    22 posts
    Registered:
    21 Jun 2010
    08 Sep 2010
    Link to this post
    Hello.  I would like to create a custom version of the standard SitefinityHyperLink control.  It would act the same way as the standard SitefinityHyperLink control with the following differences:
    - Remove/Make invisible the "Select" buttons next to ImageURL and NavigateURL (for reasons unique to our design, users shouldn't be able to see all the content these browse)
    - Default the Target value to "blank", so that the default is a new page window.

    Any help is greatly appreciated!

    Thanks,
    John
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Sep 2010
    Link to this post
    Hello John,

    NavigateUrl and Target are properties that comes form ASP.NET HyperLink control and they cannot be overridden. NavigateUrl uses System.Web.UI.Design.UrlEditor WebEditor which also comes from the base class and cannot be removed. You can create a custom class that inherits from SitefinityHyperLink and inside RenderContents method you can set the Target property to "_blank". If these changes are essential for you, you will need to create a custom control that acts in similar way as the standard ASP.NET HyperLink control and our SitefinityHyperLink.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. John
    John avatar
    22 posts
    Registered:
    21 Jun 2010
    10 Sep 2010
    Link to this post
    Thanks for the help Ivan.  We went with a custom HyperLink control with just a couple basic properties that we needed.  I will post the code in case it's useful to anyone else.  Also, I have a followup question with regards to ImageURL.

    CustomHyperLink.ascx (hardcoded target=_blank here for always-new-window functionality)
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomHyperLink.ascx.cs" Inherits="UserControls_CustomHyperLink" %>
    <div id="Div1" runat="server">
    <asp:HyperLink ID="lnkHyperLink" runat="server" Target="_blank"></asp:HyperLink>
    </div>

    CustomHyperLink.ascx.cs
    public partial class UserControls_CustomHyperLink : System.Web.UI.UserControl
    {
        private string _LinkText;
        private string _NavigateURL;
      
        public string LinkText
        {
            get { return _LinkText; }
            set { _LinkText = value; }
        }
          
        // We use a custom web editor for NavigateURL selection, commented out for post
        // [Telerik.Cms.Web.UI.WebEditor("ABW_SelectNavigateURLWebEditor,App_Code")]
        public string NavigateURL
        {
            get { return _NavigateURL; }
            set { _NavigateURL = value; }
        }
      
        // Sitefinity automatically converts a property with an enum type to a dropdown
        public AlignType Align { get; set; }
        public enum AlignType { Center, Left, Right }
      
        protected void Page_Load(object sender, EventArgs e)
        {
            lnkHyperLink.NavigateUrl = this.NavigateURL;
            lnkHyperLink.Text = this.LinkText;
            Div1.Style.Add("text-align", Align.ToString().ToLower());
        }
    }

    Then uploaded the control through the Upload Control method.
  4. John
    John avatar
    22 posts
    Registered:
    21 Jun 2010
    10 Sep 2010
    Link to this post
    My next question: With the above scenario, is there a way we can write a WebEditor for the asp:HyperLink ImageURL property where we can pass it a path to a Selected image?  I know how to bring back the image GUID, but setting that as the ImageURL for the control obviously wouldn't do much good.
  5. John
    John avatar
    22 posts
    Registered:
    21 Jun 2010
Register for webinar
5 posts, 0 answered