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>>>
57
Product 57
Full description for product number 57
114.00 $
58
Product 58
Full description for product number 58
116.00 $
59
Product 59
Full description for product number 59
118.00 $
60
Product 60
Full description for product number 60
120.00 $
61
Product 61
Full description for product number 61
122.00 $
62
Product 62
Full description for product number 62
124.00 $
63
Product 63
Full description for product number 63
126.00 $
64
Product 64
Full description for product number 64
128.00 $
65
Product 65
Full description for product number 65
130.00 $
66
Product 66
Full description for product number 66
132.00 $
67
Product 67
Full description for product number 67
134.00 $
68
Product 68
Full description for product number 68
136.00 $
69
Product 69
Full description for product number 69
138.00 $
70
Product 70
Full description for product number 70
140.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)

    {

    }

}