Contents tagged with PAGING
-
Fully Accessible And SEO Friendly Ajax Paging Using DataPager
Hey All,
Working on my current project I implemented paging using a listview and a datapager. I then decided it would be much nicer to use AJAX for my paging so wrapped all this up in an updatepanel. Next step was the issue when you would goto a page, select a product and hit the browser back button you would get the first page not the page you were last on. To fix this I simply implemented the ASP.NET AJAX Futures History control which allowed me to save my current page and restore this at a later time.
Perfect I thought until I started thinking about SEO, now my product catalogue was dead to a search engine as it would only see the first page and not be able to do any further paging. To fix this I went about creating a SEO friendly linkbutton control (I have blogged about this a while back but this is the first time I used it in real life). Basically what the SEO Friendly linkbutton does is render a normal navigateURL and the postback as an onclick. This way with Javascript turned on you get a postback but without you have a normal URL, in my case I am passing the page # in my url like so: http://site.com/catalogue/page-XX/Whatever.aspx, I am using URL Rewriter.NET for my URL rewriting so making a nice URL for this was as simple as adding a new rule into my web.config.
Firstly here is my custom SEOLinkButton control (Its in VB.NET as is my current project, I have a C# version too but will just post the VB.NET version unless requested):
Public Class SEOLinkButton
Inherits LinkButton
#Region "Properties"
Public Property NavigateURL() As String
Get
Return If(ViewState("NavigateURL") Is Nothing, "", ViewState("NavigateURL").ToString())
End Get
Set(ByVal value As String)
ViewState("NavigateURL") = value
End Set
End Property
#End Region
Protected Overrides Sub AddAttributesToRender(ByVal writer As System.Web.UI.HtmlTextWriter)
If (Me.Page IsNot Nothing) Then
Me.Page.VerifyRenderingInServerForm(Me)
End If
Me.EnsureID()
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
If (Not String.IsNullOrEmpty(Me.CssClass)) Then
writer.AddAttribute(HtmlTextWriterAttribute.Class, Me.CssClass)
End If
If (Not Me.Enabled) Then
writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled")
End If
If (Not String.IsNullOrEmpty(Me.NavigateURL) AndAlso Me.Enabled) Then
' Set the href to be our navigateUrl.
writer.AddAttribute(HtmlTextWriterAttribute.Href, Me.ResolveUrl(Me.NavigateURL))
End If
If (Me.Enabled) Then
Dim customScript As String = Me.OnClientClick
If (customScript.Length > 0 AndAlso Not customScript.EndsWith(";")) Then
customScript = customScript + ";"
End If
Dim opts As PostBackOptions = Me.GetPostBackOptions()
Dim evt As String = Nothing
If (opts IsNot Nothing) Then
evt = Me.Page.ClientScript.GetPostBackEventReference(opts)
End If
' The onclick now becomes our postback, and the appended custom script.
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, String.Format("{0}; {1} return false;", evt, customScript))
End If
End Sub
End Class