inheritance in Ucer control

Topics: General
Mar 20, 2011 at 10:36 AM

Hi

Is there a smart way in Ucercontrol for getting the pageID, or any other metadata for the page.

Can i inheriting a class or any thing like that?

Mar 20, 2011 at 1:31 PM

You can use

PageRenderer.CurrentPage

to get the current IPage-object and then the following Extension Methods to get any metadata from that

public static class IPageExtensions
    {
        public static T GetProperty<T>(this IPage page) where T : class, IPageData
        {
            using (var conn = new DataConnection())
            {
                return conn.Get<T>().FirstOrDefault(t => t.PageId == page.Id);
            }
        }

        public static IEnumerable<T> GetProperties<T>(this IPage page) where T : class, IPageData
        {
            using (var conn = new DataConnection())
            {
                return conn.Get<T>().Where(t => t.PageId == page.Id);
            }
        }
    }

with this you can fetch a single MetaData instance on your currentpage like this

 var myMetaData = PageRenderer.CurrentPage.GetProperty<IYourType>();

 

Mar 20, 2011 at 2:20 PM

If I want to use  PageRenderer.CurrentPage, what class do my User Control have to include?

 

Or is it an function I have to call?

Mar 20, 2011 at 2:24 PM

PageRenderer is the class... you should be able to right-click on it in your IDE and make it import the namespace you need. Otherwise the namespaces should be Composite.Core.WebClient.Renderings and Composite.Core.WebClient.Renderings.Page.