More in this section

Forums / Developing with Sitefinity / Gettinng a Reference to Current Object in Control Templates

Gettinng a Reference to Current Object in Control Templates

10 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    11 Mar 2009
    Link to this post
    Hello,

    I'm working with LibraryItemEdit.ascx and would like to get info on the image.

    For example, LibraryManager's GetImages() method allows access to individual images as a list of IContent(?) objects. I would like to get a reference to the IContent object for the item currently being edited in a code block within LibraryItemEdit.ascx.

    Any guidence is appreciated.

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Mar 2009
    Link to this post
    Hi Jeff,

    I cannot come up with a solution that you will be able to get a GenericContent Item that is being edited.

    All the best,
    Ivan Dimitrov
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    16 Mar 2009
    Link to this post
    I figured this one out myself. The trick is that the GUID for the image is one of the URL parameters called "Param."

    Knowing that, it's just a matter of extracting the GUID and using LibraryManager's GetContent method.

    Here's some sample code:

    LibraryItemEdit.ascx
    <% 
        if (Request.Params["Param"] != null
        { 
            Telerik.Libraries.LibraryManager lm = new Telerik.Libraries.LibraryManager(); 
            Telerik.Cms.Engine.IContent CurrentImage = lm.GetContent(new Guid((string)Request.Params["Param"])); 
            if (CurrentImage != null
                Response.Write(string.Format("Image File Name: {0}<br />Image Description: {1}<br />Height: {2}<br />Width: {3}<br />"
                    CurrentImage.Url, CurrentImage.GetMetaData("Description"), 
                    CurrentImage.GetMetaData("Height"), CurrentImage.GetMetaData("Width"))); 
        } 
    %> 

  4. ColinBowern
    ColinBowern avatar
    20 posts
    Registered:
    12 Aug 2012
    18 Mar 2009
    Link to this post
    I am hitting the same issue with the blogs as I try to add a small piece of functionality to~26nbsp~3bContentViewSingleItem.ascx - but so far I can~27t find the GUID for the item. Any thoughts on the blog module~3f~3cbr /~3e
  5. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    18 Mar 2009
    Link to this post
    I haven't yet ventured into the Blogs module but do you see a Param=<a guid> in your browser's address bar when viewing the page? If so, you should be able to use code similar to what I posted.
  6. ColinBowern
    ColinBowern avatar
    20 posts
    Registered:
    12 Aug 2012
    18 Mar 2009
    Link to this post
    Nope.  I attached a debugger and walked through the stack.  The best I could find was a content ID that returned nothing when I used GetContent.
  7. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    18 Mar 2009
    Link to this post
    You don't need a debugger to look in your web browser's address bar. I'm talking about the text box up top where you type in www.sitefinity.com, for example.

    If you browse to the blog page in question, look in the address bar for a string that reads "Param=..." If it's there, that's the Guid for your blog post.

    Just use the Request.Params["Param"] code to plug the Guid into the GetContent() call.
  8. ColinBowern
    ColinBowern avatar
    20 posts
    Registered:
    12 Aug 2012
    19 Mar 2009
    Link to this post
    Hey Jeff

    The blog module uses a rewrite service which hides all of those details.  That's why I wanted to check the Context.Items collection to see if I could find any references.  I tried poking around the assemblies with Reflector as well, but didn't have enough time to trace the activity. 

    Cheers,
    Colin
  9. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    19 Mar 2009
    Link to this post
    I see what you mean. The control I'm working with is in the Admin section of the site.

    I'm still pretty new to this stuff. I just found something that worked for me in my situation. Sorry I can't be of more help.

    Jeff
  10. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    19 Mar 2009
    Link to this post
    Hello,

    For the public part, you might try with this approach:
    1. Create a Custom BlogPosts control, which inherits from BlogPosts. Create a new class in App_Code:
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Linq; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Xml.Linq; 
    using Telerik.Blogs.WebControls; 
    using Telerik.Cms.Engine; 
     
    /// <summary> 
    /// Summary description for CustomBlogPosts 
    /// </summary> 
    namespace Telerik.Samples 
        public class CustomBlogPosts : BlogPosts 
        { 
            Guid yourItem = new Guid(); 
            public CustomBlogPosts() 
            { 
                // 
                // TODO: Add constructor logic here 
                // 
                //base.SingleItemTemplatePath = "~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx"; 
                //base.ItemListTemplatePath = "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx"; 
            } 
            public override string SingleItemTemplatePath 
            { 
                get 
                { 
                    if (base.SingleItemTemplatePath == null
                        return "~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx"
                    return base.SingleItemTemplatePath; 
                } 
                set 
                { 
                    base.SingleItemTemplatePath = value; 
                } 
            } 
            public override string ItemListTemplatePath 
            { 
                get 
                { 
                    if (base.ItemListTemplatePath == null
                        return "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx"
                    return base.ItemListTemplatePath; 
                } 
                set 
                { 
                    base.ItemListTemplatePath = value; 
                } 
            } 
            protected override void CreateSingleContent() 
            { 
                base.CreateSingleContent(); 
                yourItem = base.itemId; 
            } 
        } 

    2. Register it in the web.config file:
    <toolboxControls> 
      <clear /> 
      <add name="CustomBlogPosts" section="Blogs"  
           type="Telerik.Samples.CustomBlogPosts, App_Code" /> 

    3. Please note that I have overridden the templates properties as well. If you do not set SingeItem/ListItems template, the templates will be resolved automatically when you publish the page.

    I hope this helps.

    Best wishes,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
10 posts, 0 answered