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>>>
43
Product 43
Full description for product number 43
86.00 $
44
Product 44
Full description for product number 44
88.00 $
45
Product 45
Full description for product number 45
90.00 $
46
Product 46
Full description for product number 46
92.00 $
47
Product 47
Full description for product number 47
94.00 $
48
Product 48
Full description for product number 48
96.00 $
49
Product 49
Full description for product number 49
98.00 $
50
Product 50
Full description for product number 50
100.00 $
51
Product 51
Full description for product number 51
102.00 $
52
Product 52
Full description for product number 52
104.00 $
53
Product 53
Full description for product number 53
106.00 $
54
Product 54
Full description for product number 54
108.00 $
55
Product 55
Full description for product number 55
110.00 $
56
Product 56
Full description for product number 56
112.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)

    {

    }

}