RadTabStrip URL Rewriting

7 posts, 0 answers
  1. Michael
    Michael avatar
    18 posts
    Member since:
    Jun 2009

    Posted 04 Oct 2010 Link to this post

    I am using radtabstrip to load in usercontrols as my content pages. Is it possible to rewrite the url address bar when a tab has been clicked?

    e.g.
    I have 3 tabs, home, products, admin.
    If the user clicks the tabs I want the url address bar to show like below.
    www.mysite.com/home
    www.mysite.com/products
    www.mysite.com/admin

    I have tried using Context.RewritePath("~/home") in the radtabstrip click event, but the address bar never changes.

    Is this possible?

    Mike
  2. Michael
    Michael avatar
    18 posts
    Member since:
    Jun 2009

    Posted 11 Oct 2010 Link to this post

    Does anyone have an idea of how to do this?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave Miller
    Dave Miller avatar
    64 posts
    Member since:
    Oct 2004

    Posted 12 Oct 2010 Link to this post

    Mike,

    Yes this will work although if you are loading your page with user controls and doing AJAX request there are a couple things that need to be done. First I am using .Net 2.0 althought  I pretty sure it will in higher versions.

    This is a little complicated but what I have done is this:

    I have all the information for the site pages in a database and I have one page "default.aspx" that renders almost all pages in my sites.

    I use a custom navagation control but you could use the tab strip such is used in the demo at:
    http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/sitenavigation/defaultcs.aspx

    Using this I would set the tab NavigateUrl property to go to your pages such as home.aspx, products.aspx, etc.

    I then intercept the request on the Application_BeginRequest function in the global.asax.

    Here I strip out the page name( which needs to be unique) such as Home, Products, Admin, etc.

    I then use this as a parameter to query the database for the page ID.

    This will return default.aspx?id=1, default.aspx?id=2, etc.

     

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpContext incoming = HttpContext.Current;
        string oldpath = incoming.Request.Path.ToLower();
        string strPageTitle = (incoming.Request.Path.ToLower().Substring(incoming.Request.Path.ToLower().LastIndexOf("/") + 1)).Replace(".aspx", "");
        string pattern = @"[^a-zA-Z]";
        string newStr = Regex.Replace(strPageTitle, pattern, "");
        NavLogic nl = new NavLogic();
        string strPageUrl = nl.QryGetPageUrl(strPageTitle);
        //SP result will will be like "default.aspx?id=9" or 0 for not found
        if (strPageUrl == "0")
        {
            incoming.RewritePath(oldpath);
        }
        else
        {
            incoming.RewritePath(strPageUrl);
        }
    }

    I then catch the Request["id"] in the Page_Load and use this to build the page. I Initially load user controls in the page load and for postbacks I reload them in the OnPreInit.

    There are issues with AJAX requests and URL Rewiting. There are different ways to handle this but I use a custom form such is described in the link below.

    http://blog.angrypets.com/2007/01/aspnet_ajax_and.html

    Hope this helps,

    Dave

     

     

  5. Michael
    Michael avatar
    18 posts
    Member since:
    Jun 2009

    Posted 12 Oct 2010 Link to this post

    Dave,

    Thank you for your reply.

    The problem I have is that when I click on the tabs and loading the user controls into the content area I am not doing a postback via the navigateURL as I don't want any page refreshes throughout my website.

    I am trying to use the ajax history control for the scriptmanager which is changing the url when I click a tab, but the url looks ugly as it includes a hash symbol to add the querystring.

    Do you know if I can change the url via ajax without a postback based on the tab clicked?

    Mike
  6. Dave Miller
    Dave Miller avatar
    64 posts
    Member since:
    Oct 2004

    Posted 12 Oct 2010 Link to this post

    Mike,

    I am not sure as to why you do not want to do a post back on the initial page load. Once you have a page loaded you could change pretty much anything via AJAX other than the actual URL. 

    I have never tried this and don't know if it's possible.

    I am very concerned about the SEO for our sites so I want the individual pages otherwise it would be just like a one page Flash site.

    In any case you would still have to deal with someone coming to a specific url in the site, such as products.aspx, and have it render correctly.

    I guess I am not sure what you are trying to accomplish.

    Regards,
    Dave
  7. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 12 Oct 2010 Link to this post

    Hello Michael,

    I highly doubt you can change the url in the broswer using ajax without having the page flash. I don't think what you want to achieve is possible with ASP.NET Ajax. You could achieve this with Silverlight, since it doesn't flash when changing from page to page.
  8. Michael
    Michael avatar
    18 posts
    Member since:
    Jun 2009

    Posted 12 Oct 2010 Link to this post

    Thank you for your suggestion.

    I have decided I will abandon this approach and use normal aspx pages for navigation and use ajax within each page to load the user controls for the content area.

    One thing in regards to the sitemappath is that if I dynamically load a user control, how can I get the sitemappath to recognise it? Would I have to implement my own breadcrumb control to recognise loading user controls?

    Mike
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017