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>>>
29
Product 29
Full description for product number 29
58.00 $
30
Product 30
Full description for product number 30
60.00 $
31
Product 31
Full description for product number 31
62.00 $
32
Product 32
Full description for product number 32
64.00 $
33
Product 33
Full description for product number 33
66.00 $
34
Product 34
Full description for product number 34
68.00 $
35
Product 35
Full description for product number 35
70.00 $
36
Product 36
Full description for product number 36
72.00 $
37
Product 37
Full description for product number 37
74.00 $
38
Product 38
Full description for product number 38
76.00 $
39
Product 39
Full description for product number 39
78.00 $
40
Product 40
Full description for product number 40
80.00 $
41
Product 41
Full description for product number 41
82.00 $
42
Product 42
Full description for product number 42
84.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)

    {

    }

}