To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here





 Home

News

Forums

Hardware

CPUs

Motherboards

Video

Guides

CPU Prices

RAM Prices

Shop



Sharky Extreme : Forums:


Go Back   Sharky Forums > General Hardware/Software > Programming, Coding, and Scripting

Programming, Coding, and Scripting Need help with questions about programming, coding, or scripting? Here's the place to ask for it.

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-30-2009, 10:34 PM   #1
humanity
Tiger Shark
 
Join Date: Nov 2002
Location: In Transit
Posts: 667
ASP.NET 3.5 / AJAX / Unique URL's

I've got a web application I'm developing based on the ASP.NET 3.5 (c#) platform. For usability and speed, I plan to develop this application with heavy integration of the AJAX Control Toolkit. I'd planned to often refresh certain areas of the page based on actions by controls in other portions of the page (perhaps within UpdatePanels, but potentially within iframes -- or some combination of the two).

The problem I'm running into is developing a good routine to manage unique URL assignment. I've read a few articles on assigning URL hashes, but I haven't quite wrapped my head around the best scheme for assigning state information to the URL and -- going one step further -- a scheme for pulling that hash back out and making sense of it.

The following articles have got me thinking in the right direction. But, not being a big JavaScript guy (which will be kicking my butt for a while at the beginning of this project), it's not taking me very far.

http://msdn.microsoft.com/en-us/magazine/cc507641.aspx
http://ajaxpatterns.org/Unique_URLs

Any ideas / resources?
humanity is online now   Reply With Quote
Old 10-31-2009, 10:24 PM   #2
humanity
Tiger Shark
 
Join Date: Nov 2002
Location: In Transit
Posts: 667
I found a solution to this problem. I will share the most helpful (and simple) portion of the solution in case anyone is interested. I am dynamically loading user controls into two different UpdatePanels, so the ScriptManager was vital in accomplishing what I needed to.

Code:
protected void ScriptManager_Navigate(object sender, HistoryEventArgs e)
        {
            string menuSection = e.State["MenuSection"];
            string contentSection = e.State["ContentSection"];

            if (String.IsNullOrEmpty(menuSection))
                RedirectControl(phMenuPlaceHolder, "~/Controls/Menu/Menu1.ascx");
            else
                RedirectControl(phMenuPlaceHolder, "~/Controls/Menu/" + menuSection + ".ascx");

            if (String.IsNullOrEmpty(contentSection))
                RedirectControl(phContentPlaceHolder, "~/Controls/Content/Content1.ascx");
            else
                RedirectControl(phContentPlaceHolder, "~/Controls/Content/" + contentSection + ".ascx");
        }
Basically, on the ScriptManager's Navigate event, I've checked to see if the URL hash contains information about which MenuSection and / or ContentSection is currently presented to the users (MenuSection and ContentSection represent two different PlaceHolders within two different UpdatePanels). Based upon the information that is available in the URL hash, I call a custom RedirectControl method with different arguments.

The other side of this is creating a browser history entry when actions are performed within the UpdatePanels (in order to allow a user to use his or her browser's forward and back buttons). I've accomplished this with the following code:

Code:
private void LoadUserControls()
        {
            string controlPath = CurrentMenuControl;
            if (!string.IsNullOrEmpty(controlPath))
            {
                phMenuPlaceHolder.Controls.Clear();
                UserControl uc = (UserControl)LoadControl(controlPath);
                uc.ID = Path.GetFileName(controlPath).Replace(".ascx", "");
                phMenuPlaceHolder.Controls.Add(uc);

                if (smScriptManager.IsInAsyncPostBack && !smScriptManager.IsNavigating)
                    smScriptManager.AddHistoryPoint("MenuSection",uc.ID);
            }

            controlPath = CurrentContentControl;
            if (!string.IsNullOrEmpty(controlPath))
            {
                phContentPlaceHolder.Controls.Clear();
                UserControl uc = (UserControl)LoadControl(controlPath);
                uc.ID = Path.GetFileName(controlPath).Replace(".ascx", "");
                phContentPlaceHolder.Controls.Add(uc);

                if (smScriptManager.IsInAsyncPostBack && !smScriptManager.IsNavigating)
                    smScriptManager.AddHistoryPoint("ContentSection", uc.ID);
            }
        }
In my LoadUserControls method, which is called from RedirectControl, I check to ensure an asynchronous postback has occurred and that the user has not forced a navigation (via the back button, for instance). If this is the case, I add a new index to the user's browser history containing keys for the current MenuSection and ContentSection respectively.

This allows for full browser history functionality and the ability to navigate to specific states in my AJAX Web application. For instance, the default page URL with MenuSection "Menu2" and ContentSection "Content1" displayed would be as follows:

Code:
http://localhost/Default.aspx#&&ContentSection=Content1&MenuSection=Menu2
**Note** Current procedures for user control ID assignment are a bit rough and could lead to problems if the filenames of the user controls being loaded in the MenuSection and ContentSection match, but that wasn't the point of this test app.

Helpful resources:
http://www.asp.net/learn/3.5-SP1/video-242.aspx (implementing AJAX history)
http://geekswithblogs.net/rashid/arc...datePanel.aspx (dynamically loading user controls)
humanity is online now   Reply With Quote
Reply

Bookmarks
Go Back   Sharky Forums > General Hardware/Software > Programming, Coding, and Scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 10:57 PM.




Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.