ManuelAbadia.com
PagerDataSource samples
Samples



Product Information

Search Engine Optimization (Part 1)

If we have a LinkButton control on a page,  the control will generate some javascript to send the page back to the server when the control is clicked. On a postback, the ASP.NET infrastructure restores the previous state of the page (saved in the view state) applying the changes made by the user before posting the form. This provides a friendly programming model for the developer but it is not search engine friendly. However, the ASP.NET programming model is not search engine friendly. The search engine spiders will not follow links that have javascript so if we are showing several paged items in a WebForm, the search engine spider will only see the items of the first page.

This is a serious problem that can cause poor positioning in search engines. The PagerDataSource was designed with this problem in mind so it provides a solution to this problem.

The Mode property of the PagerDataSource is set by default to "PostBack". This will cause the control to render a LinkButton for each clickable item of the pager. This lets the developer maintain the usual ASP.NET programming model. However, if we want to improve our presence in search engines we can set the Mode property to "QueryStringRedirect". When the Mode property is set to "QueryStringRedirect", a clickable item on the pager is rendered as an HyperLink to the current page, and a parameter is added to the query string to let the PagerDataSource know the selected page. The implications of this mode are that when we click on an item to change the actual page, the same page is requested again (a postback is not performed) so when the page executes, the property IsPostback of the Page will return "false" and the view state will be empty. Keep that in mind when you are developing using the "QueryStringRedirect" mode.

In "QueryStringRedirect" mode as in "PostBack" mode, we can have multiple pagers synchronized to provide a better navigation. However, if we want to have several synchronized pagers for different controls we need to specify the property PageKey of the PagerDataSource to a common string for each group pagers. Why? When the PagerDataSource generates the URLs for the page links, it has to set a query string pair like Page=5. By default, all pagers use the key Page to specify the selected page. For example, if we have two pagers for a DataList and two pagers for a Repeater, set the PageKey for the pagers associated with the DataList to Page1 and the PageKey for the pagers associated with the Repeater to Page2. That way the query string will be like Page1=3&Page2=6 and all the pagers will be synchronized as expected.

The sample "Search Engine Optimization (2)" contains more information about how to further optimize a pager for better search engine positioning.

The source code for this page is shown after the live sample.


Product List

<<<1|2|3|4|5|6|7|8>>>
1
Product 1
Full description for product number 1
2.00 $
2
Product 2
Full description for product number 2
4.00 $
3
Product 3
Full description for product number 3
6.00 $
4
Product 4
Full description for product number 4
8.00 $
5
Product 5
Full description for product number 5
10.00 $
6
Product 6
Full description for product number 6
12.00 $
7
Product 7
Full description for product number 7
14.00 $
8
Product 8
Full description for product number 8
16.00 $
9
Product 9
Full description for product number 9
18.00 $
10
Product 10
Full description for product number 10
20.00 $
11
Product 11
Full description for product number 11
22.00 $
12
Product 12
Full description for product number 12
24.00 $
13
Product 13
Full description for product number 13
26.00 $
14
Product 14
Full description for product number 14
28.00 $
<<<1|2|3|4|5|6|7|8>>>

Sample source code

The ASPX file for this sample is:.


<%@ Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="SearchEngineOptimization1.aspx.cs" Inherits="SearchEngineOptimization1" Title="Search Engine Optimization" %>


<%
@ Register Assembly="PagerDataSource" Namespace="Manu.Web.UI.WebControls" TagPrefix="manu" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="Content" Runat="Server">

    <h2>Product List</h2>

 

    <manu:PagerDataSource ID="PagerDataSource1" runat="server"

        DataSourceID="ObjectDataSource1" PageSize="14" Mode="QueryStringRedirect">

    </manu:PagerDataSource>

 

    <asp:DataList ID="DataList1" runat="server"

        DataKeyField="id" DataSourceID="PagerDataSource1"

        RepeatColumns="7" RepeatDirection="Horizontal" Width="100%">

        <ItemTemplate>

            <table>

                <tr>

                    <td align="center">

                        <asp:Label ID="idLabel" runat="server"

                        Text='<%# Eval("id") %>'></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td align="center">

                        <b><asp:Label ID="nameLabel" runat="server"

                        Text='<%# Eval("name") %>'></asp:Label></b>

                    </td>

                </tr>

                <tr>

                    <td align="center">

                        <asp:Label ID="descriptionLabel" runat="server"

                        Text='<%# Eval("description") %>'></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td align="center">

                        <asp:Label ID="priceLabel" runat="server"

                        Text='<%# Eval("price", "{0:#0.00}") %>'>

                        </asp:Label> $

                    </td>

                </tr>

            </table>

        </ItemTemplate>

        <ItemStyle BackColor="White" ForeColor="#436799" />

    </asp:DataList>

 

    <manu:PagerDataSource ID="PagerDataSource2" runat="server"

        DataSourceID="PagerDataSource1" PageSize="14" Mode="QueryStringRedirect">

    </manu:PagerDataSource>

 

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="ProductsDAL"

        SelectMethod="GetPagedData" SelectCountMethod="CountAll" EnablePaging="True"

        MaximumRowsParameterName="maxRows" StartRowIndexParameterName="startIndex">

    </asp:ObjectDataSource>

</asp:Content>


The code-behind file (ASPX.CS) is:


using System;

 

public partial class SearchEngineOptiomization1 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

}