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>>>
71
Product 71
Full description for product number 71
142.00 $
72
Product 72
Full description for product number 72
144.00 $
73
Product 73
Full description for product number 73
146.00 $
74
Product 74
Full description for product number 74
148.00 $
75
Product 75
Full description for product number 75
150.00 $
76
Product 76
Full description for product number 76
152.00 $
77
Product 77
Full description for product number 77
154.00 $
78
Product 78
Full description for product number 78
156.00 $
79
Product 79
Full description for product number 79
158.00 $
80
Product 80
Full description for product number 80
160.00 $
81
Product 81
Full description for product number 81
162.00 $
82
Product 82
Full description for product number 82
164.00 $
83
Product 83
Full description for product number 83
166.00 $
84
Product 84
Full description for product number 84
168.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)

    {

    }

}