ASPX templates
Version 5.x > ASPX templates > UniPager View modes: 
User avatar
Member
Member
eric.rovtar - 3/22/2011 11:21:51 AM
   
UniPager
Hi!

Is there a way to hide the PreviousPage link if you're on the first page using the UniPager?

<PreviousPageTemplate>
<a href="<%# Eval("PreviousURL") %>"><< back</a>
</PreviousPageTemplate>

Basically, I'd like to add a condition to the PreviousPageTemplate. Can I do that? And if I can, how and what condition would I be looking for?

Thanks!

User avatar
Member
Member
kentico_michal - 3/25/2011 10:00:00 AM
   
RE:UniPager
Hi Eric,

Regrettably, it is not possible to disable PreviousPageTemplate for the first page. You could consider creating custom method which would return link to previous page based on the current page. For example, this method could return link to previous page on all pages except the first one.

Please take a look at following code snippet:


<cms:UniPager ID="UniPager" runat="server" PageControl="CMSRepeater" PageSize="2" DisplayPreviousNextAutomatically="false" >

<PageNumbersTemplate>
<a href="<%# Eval("PageURL") %>"><%# Eval("Page") %></a>
</PageNumbersTemplate>

<PreviousPageTemplate>
<%# getPreviousURLLink(Eval("Page"), Eval("PreviousURL"))%>
</PreviousPageTemplate>

</cms:UniPager>


CODE BEHIND:


protected string getPreviousURLLink(object Page, object PreviousURL)
{
string output = "";
string currentPage = CMS.GlobalHelper.ValidationHelper.GetString(Page, "");
if (currentPage != "1")
{
output = "<a href=" + CMS.GlobalHelper.ValidationHelper.GetString(PreviousURL, "") + "> back </a>";
}
return output;
}


Best regards,
Michal Legen

User avatar
Member
Member
eric.rovtar - 3/25/2011 10:03:44 AM
   
RE:UniPager
Thanks, Michal. That's what I was looking for!

User avatar
Member
Member
eric.rovtar - 4/6/2011 5:28:55 PM
   
RE:UniPager
Ok... I guess this would be the logical follow-up: How do I tell if it's the last page? Thanks!

User avatar
Member
Member
kentico_michal - 4/7/2011 6:37:18 AM
   
RE:UniPager
Hello Eric,

You could try to use following code:

<cms:UniPager ID="UniPager" runat="server" PageControl="CMSRepeater" PageSize="2" DisplayPreviousNextAutomatically="false" >

<PageNumbersTemplate>
<a href="<%# Eval("PageURL") %>"><%# Eval("Page") %></a>
</PageNumbersTemplate>

<NextPageTemplate >
<%# getNextURLLink(Eval("NextURL"))%>
</NextPageTemplate>

</cms:UniPager>


<script runat="server" >
protected string getNextURLLink(object NextURL)
{
string output = "";
string currentPage = CMS.GlobalHelper.ValidationHelper.GetString(this.UniPager.CurrentPage, "");
if (currentPage != this.UniPager.PageCount.ToString())
{
output = "<a href=" + CMS.GlobalHelper.ValidationHelper.GetString(NextURL, "") + "> next </a>";
}
return output;
}
</script>


I hope this will help you.


Best regards,
Michal Legen

User avatar
Member
Member
eric.rovtar - 4/18/2011 2:28:30 PM
   
RE:UniPager
Michal:

Is there a way to do this in the code-behind? The hold up would probably be the "this.UniPager.PageCount.ToString()" call.

Thanks!

User avatar
Member
Member
kentico_michal - 4/22/2011 1:55:49 AM
   
RE:UniPager
Hello Eric,

The UniPager control does not provide properties like PageCount, PreviousURL, NextURL and therefore you are not able to access them in the code behind. The only way how to access them is to pass them as input parameters to getPreviousURLLink and getNextURLLink.

Best regards,
Michal Legen

User avatar
Member
Member
eric.rovtar - 4/22/2011 10:15:07 AM
   
RE:UniPager
Thanks, Michal. I was thinking this through, but couldn't I create my own WebPart or ASPX Control that sets up the UniPage and contains these functions then? This would then allow me to add the same Pager styles to multiple pages. The only variable I would need to even pass it would be the Control ID.

Thanks again!

User avatar
Member
Member
kentico_michal - 4/26/2011 6:03:31 AM
   
RE:UniPager
Hello Eric,

It is possible to create UniPager web part and modify it according to your needs or add functions that has been posted in this forum.

Moreover, there is already a web part called Universal pager, so you might find some inspiration in ~\CMSWebParts\Viewers\Basic\UniPager.ascx.

Please read following article, if you need more information about Developing web parts.

Best regards,
Michal Legen

User avatar
Member
Member
phil-fourleaf.co - 5/13/2011 6:21:44 AM
   
RE:UniPager
Silly question guys can you not just use something like the following in the transformation, or am I missing something?

<%# (Eval("PreviousURL").ToString().IndexOf("page="+Request.QueryString["page"]) > -1 ? "<span class='previous_disabled'>Previous</span>" : "<a href='" + Eval("PreviousURL", true) + "' class='previous'>Previous</a>" ) %>

To hide the next link is little more complicated because the null qs value needs to be checked (null in initial page load):

<%# (Eval("NextURL").ToString().IndexOf("page="+(Request.QueryString["page"] == null ? "0" : Request.QueryString["page"])) < 0 ? "<a href='" + Eval("NextURL", true) + "' class='next'>Next</a>" : "<span class='next_disabled'>Next</span>" ) %>

Cheers,
Phil

User avatar
Member
Member
kentico_michal - 5/16/2011 5:13:31 AM
   
RE:UniPager
Hello Phil,

Thank you very much for posting this nice solution. I believe that many users find it useful.

Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 2/10/2012 9:02:34 AM
   
RE:UniPager
Wow! Thanks so much for this solution! Works perfectly!

User avatar
Certified Developer 8
Certified Developer 8
ana@endora.hr - 8/22/2013 8:50:40 AM
   
RE:UniPager
Hi Eric,

here is another solution. I hope this will help somebody cause solution with IndexOf didn't work for us. We are using v7.0.15 Kentico so maybe something was changed since that solution.

OK this is our code.


<div class="prevnextPager">

<!-- this is just for testing purposes -->
current: <%# GetAbsoluteUrl(Request.RawUrl) %> <br />
prev: <%# GetAbsoluteUrl(Eval("PreviousURL").ToString()) %><br />
next: <%# GetAbsoluteUrl(Eval("NextURL").ToString()) %><br />

<-- ** Request.RawUrl will output the URL with query string -->

<!-- end of testing -->


<!-- Previous Page -->
<asp:PlaceHolder runat="server" ID="plcPreviousPage">
<%# (GetAbsoluteUrl(Request.RawUrl) == GetAbsoluteUrl(Eval("PreviousURL").ToString())) ? "" : "<a href='" + Eval("PreviousURL", true) +"'>Previous Image</a>" %>
</asp:PlaceHolder>


<!-- Next Page -->
<asp:PlaceHolder runat="server" ID="plcNextPage">
<%# (GetAbsoluteUrl(Request.RawUrl) == GetAbsoluteUrl(Eval("NextURL").ToString())) ? "" : "<a href='" + Eval("NextURL", true) +"'>Next Image</a>" %>
</asp:PlaceHolder>

</div>