Problem with Keyword-Rich Paging using UrlRewriter

9 posts, 1 answers
  1. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 09 Jan 2010 Link to this post

    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
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 13 Jan 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 14 Jan 2010 Link to this post

    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
  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 15 Jan 2010 Link to this post

    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.
  6. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 16 Jan 2010 Link to this post

    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
  7. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 20 Jan 2010 Link to this post

    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.
  8. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 22 Jan 2010 Link to this post

    Nikolay,

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

    Ronnie
  9. Rutger Buijzen
    Rutger Buijzen avatar
    21 posts
    Member since:
    Nov 2006

    Posted 30 Mar 2012 Link to this post

    Would you please be so kind to extend this example code to cover first, last, previous and next buttons?

    Thanks in advance!
  10. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 04 Apr 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017