This is a migrated thread and some comments may be shown as answers.

Problem with Keyword-Rich Paging using UrlRewriter

8 Answers 132 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ronnie
Top achievements
Rank 1
Ronnie asked on 09 Jan 2010, 10:09 AM
Hello,

I've successfully converted an asp:ListView with a custom Pager to the RadListView with the RadDataPager.
I've set AllowSEOPaging="true" and SEOPagingQueryPageKey="Page"

My original custom pager created a URL using UrlRewriter to something like this..:

http://www.sitename.com?DepartmentId=1&CategoryId=1&Page=2  to: 
http://www.sitename.com/Dept-Name-d1/Cat-Name-c1/Page-1/

In order to do this, I pass the querystring params to a method and it does the rewriting, in this case a method like:

currentLink.NavigateUrl = UrlClass.LinkToCategory(DepartmentId, CategoryId, PageNumber);

Unfortunately, when using the RadDataPager, it converts the intial Url that is UrlRewriten back to a dynamic one.
I have created the following in the PreRender event of the RadDataPager and tested it with static values and it works.
protected void RadDataPager1_PreRender(object sender, EventArgs e) 
   RadDataPager dataPager = (RadDataPager)lvwProducts.FindControl("RadDataPager1"); 
 
   foreach (Control control in dataPager.Controls) 
   { 
      foreach (Control c in control.Controls) 
      { 
         if (c is HyperLink) 
         { 
            HyperLink currentLink = (HyperLink)c; 
            currentLink.NavigateUrl = UrlClass.LinkToCategory("1""1""2"); // <--- This rewrites properly.
            // TODO: Put Page Command Value into PageNumber parameter.
            currentLink.NavigateUrl = UrlClass.LinkToCategory(DepartmentId, CategoryId, PageNumber); 
         } 
      } 
   } 

My question is how can I access the DataPager commands (First, Last, Previous, Next, etc..) to pass as a parameter for the PageNumber in the above method?

Thank you,
Ronnie

8 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 13 Jan 2010, 04:48 PM
Hello Ronnie,

You should change the HyperLink buttons NavigationUrl on FieldCreated. For your convenience I have prepared sample application demonstrating this. Please find it attached to this post.

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ronnie
Top achievements
Rank 1
answered on 14 Jan 2010, 07:33 AM
Thank you for your response Nikolay,

Unfortunately this didn't work the way expected.  I'm using UrlRewriter.net and my 'UrlClass' does all the work in creating the url, (specifically the LinkToCategory method), where it converts the parameters integer value to its named value.  And then the format is detailed in the web.config in <rewriter> section.

By passing the parameter values, like so:

int DeptId = 1;   <----- I can get and pass this parameter
int CatId = 2;     <----- I can get and pass this parameter
int Page = 2;     <----- I NEED THIS VALUE.  Is there a client side way to access the field that is being clicked (Next, Prev, 1,2,3, etc..) and pass it's value to the FieldCreated event or other event ?

currentLink.NavigateUrl = UrlClass.LinkToCategory(DeptId, CatId, Page);   -----> returns: 
http://www.localhost.com/Concerts-d1/Rock-and-Pop-c2/Page-2/

Thank you again,
Ronnie
0
Nikolay Rusev
Telerik team
answered on 15 Jan 2010, 04:08 PM
Hello Ronnie,

Using UrlRewriter.net  all you need to do is set properly rules and change the urls in RadDataPager.Unfortunately you will have to parse already builded NavigationUrl and transform it to format that fits your needs. For your convenience I've changed the demo from my last post to use UrlRewriter.net.

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ronnie
Top achievements
Rank 1
answered on 16 Jan 2010, 06:51 AM
Once again thank you for your assistance, but I'm still having problems.
It is that the RadDataPager returns the friendly names querystring to its default state. 
eg: DepartmentId=1&CategoryId=2, instead of Concerts-d1/Rock-and-Pop-c2. 

When you said that I need to parse the already built NavigateUrl what exactly where you thinking..?
Is there a way to get the SEOPagingQueryPageKey="PageTo" and its value by itself into a string?  Without the rest of the querystring list?

I can then combine them and do:
currentLink.NavigateUrl = UrlClass.LinkToCategory(DepartmentId, CategoryId) + "PageTo-";

I just don't know how to get the PageTo value separately.

Thank you again,
Ronnie
0
Accepted
Nikolay Rusev
Telerik team
answered on 20 Jan 2010, 04:28 PM
Hello Ronnie,

For your convenience I've prepared example of how you can create custom RadDataPagerButtonField. By changing the code in UrlBuilder method you will be able build the navigation url for numeric buttons on your own in manner that fits your needs. Currently in the project the code is using default method for building this urls - you can change this.

Please find the attached application to this thread.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ronnie
Top achievements
Rank 1
answered on 22 Jan 2010, 06:43 AM
Nikolay,

That's what I needed...!!!  : )
Thank you so much for your time and assistance.  It is very much appreciated.

Ronnie
0
Rutger Buijzen
Top achievements
Rank 2
answered on 30 Mar 2012, 10:14 AM
Would you please be so kind to extend this example code to cover first, last, previous and next buttons?

Thanks in advance!
0
Tsvetina
Telerik team
answered on 04 Apr 2012, 12:26 PM
Hello Rutger,

The approach would be identical for the First/Last/Next/Prev buttons, you just need to override the respective method of the RadDataPagerButtonField in the custom class that you implement. For example, for first button it would look like this:
public class CustomDataPagerFirstButtonField : RadDataPagerButtonField
{
    protected override Control CreatenFirstButton(PagerFieldButtonType buttonType)
    {  
        //create HyperLink
        HyperLink button = new HyperLink();
        //need to wrap the content with "span" for rounding effect
        button.Text = String.Format("<<");
        button.CssClass = "rdpPageFirst";
        //build the navigation URL - extensibility point
        button.NavigateUrl = UrlBuilder("First");
 
        return EnsureEnableState(button as WebControl, "First");
    }
     
    protected string UrlBuilder(string commandArgument)
    {
 
        //SEOPagingLinkBuilder builds the URL for a button
        //you can comment it and add your custom implementation for handling the process of building navigation urls
 
        return SEOPagingLinkBuilder(commandArgument);
    }
}


Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Ronnie
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Ronnie
Top achievements
Rank 1
Rutger Buijzen
Top achievements
Rank 2
Tsvetina
Telerik team
Share this question
or