![]() |
Sharky Extreme : Forums: |
|
![]() |
| ||||||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
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? |
|
|
|
|
|
#2 |
|
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");
}
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);
}
}
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 ![]() 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) |
|
|
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|