More in this section

Forums / Developing with Sitefinity / ContentView Pager

ContentView Pager

5 posts, 1 answered
  1. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    24 Feb 2010
    Link to this post
    Hi Ivan & co,

    Is there a way to directly access the SingleItem control of a ContentView's Pager (a RepeaterItem)?

    I have tried to access the Pager directly, and although I can get a reference to the Pager by doing:

    protected Pager Pager1
    {
        get { return ListContainer.GetControl<Pager>("pager1", true); }
    }

    The Pager1 reference works fine, but when trying to access either the PagerRepeaterHyperLink or PagerRepeaterLinkButton properties, an object reference not found exception is thrown.

    My pager template looks like this:

    <sfWeb:Pager ID="pager1" runat="server">
        <LayoutTemplate>
             <asp:Repeater ID="PageRepeaterLinkButton" runat="server">
                <HeaderTemplate>
                    <ol class="pager">
                    <li><asp:LinkButton ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:LinkButton></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:LinkButton ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:LinkButton ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:LinkButton></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
            <asp:Repeater ID="PageRepeaterHyperLink" runat="server">
                <HeaderTemplate>
                    <ol class="pager">
                    <li><asp:HyperLink ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:HyperLink></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:HyperLink ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:HyperLink></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
        </LayoutTemplate>
    </sfWeb:Pager>

    I need to access the SingleItem, NextPage and PreviousPage's NavigateUrl property and re-format it for each item, as it is formatting the current querystring incorrectly due to the lack of UrlEncode() being applied to QueryString values.


    Regards,
    Alvaro
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hello Alvaro,

    You do not have to create control reference to the pages, since you can access it from the container. The problem here is that you will not be able to subscribe for ItemDataBound event of the repeaters.
    There is one way to access the HyperLinks, but it is not good. However I am pasting the code below

    protected override void OnPreRender(EventArgs e)
       {
           base.OnPreRender(e);
           this.ListContainer.Pager1.PreRender += new EventHandler(Pager1_PreRender);
           
       }
     
       void Pager1_PreRender(object sender, EventArgs e)
       {
           // get one of the controls from the pager
           // you need to get the index first then loop through
           // controls
           var it = ((System.Web.UI.WebControls.RepeaterItem)(((Telerik.Cms.Web.UI.Pager)(sender)).PagerRepeaterHyperLink.Controls[3]));
           HyperLink link = ((System.Web.UI.Control)(it)).Controls[1] as HyperLink;
       }


    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.
    Answered
  3. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    24 Feb 2010
    Link to this post
    Hi Ivan,

    I will investigate that path, many thanks.


    Regards,
    Alvaro
  4. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    25 Mar 2010
    Link to this post
    Hi Ivan,

    I've got around to trying to fix this problem today, but I'm finding that PagerRepeaterHyperLink property of the Pager is null during the pre-render event, using the following code:

    /// <summary>
    /// OnPreRender event handler override
    /// </summary>
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.ListContainer.Pager1.PreRender += new EventHandler(Pager1_PreRender);
    }
    /// <summary>
    /// Pager1 PreRender event handler
    /// </summary>
    private void Pager1_PreRender(object sender, EventArgs e)
    {
        Telerik.Cms.Web.UI.Pager pager = (Telerik.Cms.Web.UI.Pager)sender;
        // pager.PagerRepeaterHyperLink is NULL!
    }

    The problem comes in the following page of our site:

    http://www.eularis.com/ja/knowledge-center/articles.aspx

    When one of the paging links is clicked, because the paging doesn't automatically prefix the current language, it defaults back to English.

    Do you have any other suggestions on how I could get the paging links to display the correct language links?


    Regards,
    Alvaro
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Mar 2010
    Link to this post
    Hi Alvaro,

    The problem has been fixed in Sitefinity 3.7 SP3. I suggest that you should upgrade your project. The problem appears when you set RenderPagerAsLink

    Regards,
    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.
Register for webinar
5 posts, 1 answered