Accessing Page Description from ascx

Posted by Community Admin on 04-Aug-2018 12:25

Accessing Page Description from ascx

All Replies

Posted by Community Admin on 23-Jun-2012 00:00

Hi,

I'm trying to migrate the Simplicity template to 5.x, and I have a problem with their custom navigation control. See the code below:

<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
<telerik:RadTabStrip ID="RadPanelbarNav" runat="server" Visible="false" />
  
<asp:Repeater  ID="Repeater1" runat="server" DataSourceID="SiteMapDataSource" >
    <HeaderTemplate>
        <ul class="nav-holder">
    </HeaderTemplate>
    <ItemTemplate>
            <li>
                <a href='<%# Eval("Url") %>' runat='server'>
                    <h3><%#Eval ("Title") %></h3>
                    <p><%#Eval("Description")%></p>
                </a>
            </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>
  
<sfMap:SitefinitySiteMapDataSource runat="server" ID="SiteMapDataSource" StartingNodeOffset="0" ShowStartingNode="false" />

I already replaced the SiteMapDataSource by the new SitefinitySiteMapDataSource, but now the expression <%#Eval("Description")%>  fails because there isn't such a property in the items provided by the datasource.

Is there a way to access the page description from the ascx file without code-behind?

Thank you,

Alexis

Posted by Community Admin on 28-Jun-2012 00:00

Hello,

That's a tough one, unfortunately there is no way to access the Description field on a PageSiteNode if you don't get the PageNode itself - SitefinitySiteMapDataSource is a special control we've developed to provide the best performance when working with custom navigation controls, as it gives you the cached output from the pages provider, and also takes care of  things like ShowInNavigation, group pages behavior etc.

However you can easily subscribe to the repeater ItemDataBound event and do something like:

protected void Page_Load(object sender, EventArgs e)
        
            Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
        
    
        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            
                var item = e.Item.DataItem as PageSiteNode;
                var pageManager = PageManager.GetManager();
                PageNode pageNode;
                using (new ElevatedModeRegion(pageManager))
                
                    pageNode = pageManager.GetPageNode(item.Id);
                
                Label descrLabel = e.Item.FindControl("descrLbl") as Label;
                if (descrLabel != null && pageNode.Page != null)
                
                    descrLabel.Text = pageNode.Page.Description.ToString();
                
            
        



Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 20-Sep-2012 00:00

Basically what I need is the description (or something else) in addition to just the page title. I found this thread and it seemed like it would work, unfortunately I'm brand new to Sitefinity, C#sharp, and I'm pretty much a front front end guy to boot. So how would I use the code you've suggested above (meaning where would I put it). Do I need a codefile in addition to the MainNavigation.ascx that Simplicity uses? or where would I put that code? Do you have another suggestion?

Thanks for your help!

Posted by Community Admin on 21-Sep-2012 00:00

Hello Richard,

Yes, the sample is actually the codefile added to the ascx template for MainNavigation.ascx.
Please note you will need to add a label with ID descrLbl on the frontend, which will be the container for the Description text.

Greetings,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 21-Sep-2012 00:00

Hey Boyan, Thanks for the input. I put the sample code in a codefile and I'm getting an error 
Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct 

Clearly I'm clueless :) I must be missing something in my codefile...

Thanks for you help!

This thread is closed