Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeric 122 posts 192 karma points
    Mar 05, 2013 @ 10:16
    Jeric
    0

    Property similar to "Link to document"

    Hi,

    I need to create a new property which will display exactly what is shown by the "Link to document" and with additional text at the end.

    Eg
    Link to document showing -      www.test.com/here/
    New property needs to show -      www.test.com/here/?alttemplate=theTemplate

    Will it be possible to create such property?

    thanks

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 05, 2013 @ 12:46
    Jeroen Breuer
    0

    Yes you could create a new datatype which does this. Here is an example to get you started (with the usercontrol wrapper):

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HyperLinkView.ascx.cs" Inherits="WebApplication.DataTypes.HyperLinkView.HyperLinkView" %>
    <asp:HyperLink ID="HplClick" runat="server"></asp:HyperLink>
    public partial class HyperLinkView : UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
        #region IUsercontrolDataEditor Members
    
        public object value
        {
            get
            {
                return HplClick.NavigateUrl;
            }
            set
            {
                if ((value != null) && (!string.IsNullOrEmpty(value.ToString())))
                {
                    HplClick.NavigateUrl = value.ToString();
                    HplClick.Text = value.ToString();
                    HplClick.Target = "_blank";
                }
            }
        }
    
        #endregion
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }

    This is a bit like the label datatype, but as a hyperlink.

    Jeroen

  • Jeric 122 posts 192 karma points
    Mar 05, 2013 @ 17:11
    Jeric
    0

    I'm kind of new on the usercontrol thingy.
    Any guide onto where or how should I start?

    Thanks  

  • Andreas Iseli 150 posts 427 karma points
    Mar 06, 2013 @ 12:06
    Andreas Iseli
    0

    It is really simple. Jeroen has already posted the code you need. You then only to copy the DLL containing the codebehind into the "bin" folder of your installation and the *.ascx file into the "usercontrols" folder of your installation.

    In the umbraco backend navigate to the developer section, right click on the "Data Types" folder and create a new datatype. Selection the "umbraco usercontrol wrapper" as Property editor. Save the data type and the select your deployed ASCX file from the usercontrol dropdown. Save again and you have successfully created your first own data type.

    Be sure to also select the correct database datatype and ensure value object you return maps this datatype.

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 14:03
    Jeric
    0

    Managed to get it working. Another thing for the below, how do I get the value of the "Link to document"
    to be used below? (the parts below with the comment)

    Thanks

     

    publicpartialclassHyperLinkView:UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
       
    #region IUsercontrolDataEditor Members

       
    publicobject value
       
    {
           
    get
           
    {
               
    returnHplClick.NavigateUrl;
           
    }
           
    set
           
    {
               
    if((value !=null)&&(!string.IsNullOrEmpty(value.ToString())))
               
    {
                   
    HplClick.NavigateUrl= value.ToString();
                   
    HplClick.Text= value.ToString();
                   
    HplClick.Target="_blank";
               
    }
           
    }
       
    }

       
    #endregion

       
    protectedvoidPage_Load(object sender,EventArgs e)
       
    {
    value = "/TestTemplate/"; // how do I get the value of the 'Link to document' here to concat with the "/TestTemplate/"?
       
    }
    }
  • Andreas Iseli 150 posts 427 karma points
    Mar 06, 2013 @ 14:17
    Andreas Iseli
    0

    I suggest to override the onload method (or even page_load, but I always preferec the control specific methods) and reading the value on postback. Use a private member value to store the value in background instead of directly referencing your web control.

    public YourClass : ....
    {
       private int _linkValue;

        public object value
       {
          get
          {
              return _linkValue;
          }
          set
          {
              if (value != null && !string.IsNullOrEmpty(value.ToString()))
              {
                 _linkValue = value.ToString();
              }
          }
       }
       
       protected override void OnLoad(EventArgs e)
       {
             if (!Page.IsPostback)
             {
                   HplClick.NavigateUrl = _linkValue;
                   HplClick.Text = _linkValue;
             }
             else
             {
                   _linkValue = HplClick.NavigateUrl;
             }
    }
    }

    If this is what you want ;-)

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 15:41
    Jeric
    0

    how do I get the value from the "Link to document"?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 06, 2013 @ 15:44
    Jeroen Breuer
    0

    If the node is published you could try something like this (might need to add some namespaces)

    var node = new Node(Convert.ToInt32(Request.Querystring["id"]));
    var linkToDocument = node.Url;

    Jeroen

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 15:49
    Jeric
    0

    The below error came out

    Error2The type or namespace name 'Node' could not be found (are you missing a using directive or an assembly reference?)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 06, 2013 @ 15:51
    Jeroen Breuer
    0

    You need to add a reference to the umbraco.dll file and than Visual Studio can resolve it for you.

    Jeroen

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 15:54
    Jeric
    0

    Kind of new in this thing, how can I add a reference to the umbraco.dll file in Visual Studio?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 06, 2013 @ 15:55
  • Andreas Iseli 150 posts 427 karma points
    Mar 06, 2013 @ 15:57
    Andreas Iseli
    0

    I suggest using the nuget package manager. And the run Install-Package UmbracoCms.Core

    Verify to get the correct version you are corrently deploying to.

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 16:38
    Jeric
    0

    still can't figure out how to get it work.

    any other way that I can get the CurrentPage's Url in the .ascx.cs file?

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 06, 2013 @ 16:41
    Jeroen Breuer
    0

    You'll need the reference to the umbraco.dll file which is in the /bin folder of you website. Maybe this can help: http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx

    Jeroen

  • Jeric 122 posts 192 karma points
    Mar 06, 2013 @ 17:10
    Jeric
    0

    good news, managed to get it all sorted out :)

     

Please Sign in or register to post replies

Write your reply to:

Draft