Hi
To simplify, I have on a page RadAjaxPanel with RadGrid inside (Rad controls for asp.net ajax Q1 2009); everything is fine till I'm placing an ajax request - refreshing the grid - then I get this error:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Global.asax code:
| void Application_Start(object sender, EventArgs e) |
| { |
| RegisterRoutes(RouteTable.Routes); |
| } |
| public static void RegisterRoutes(RouteCollection Routes) |
| { |
| Routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler())); |
| var routeHandler = new WebFormRouteHandler<Page>("~/Desktop/Default.aspx"); |
| Routes.Add(new Route("pg/{page}", routeHandler)); |
| } |
Handler:
| public class WebFormRouteHandler<T> : IRouteHandler where T : IHttpHandler, new() |
| { |
| public string VirtualPath { get; set; } |
| public WebFormRouteHandler(string virtualPath) |
| { |
| this.VirtualPath = virtualPath; |
| } |
| #region IRouteHandler Members |
| public IHttpHandler GetHttpHandler(RequestContext requestContext) |
| { |
| string pageName |
| = requestContext.RouteData.GetRequiredString("page"); |
| if (!pageName.Contains(".axd") && pageName.Contains(".aspx")) |
| { |
| pageNamepageName = pageName.Replace(".aspx", ""); |
| string virtualPath |
| = ObjectContentValidator.StringIsNullOrEmpty(pageName) |
| ? "~/desktop/default.aspx" |
| : string.Format("~/desktop/default.aspx?page={0}", pageName); |
| HttpContext.Current.RewritePath(virtualPath, false); |
| return (T)BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(T)); |
| } |
| else |
| return (VirtualPath != null) |
| ? (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(T)) |
| : new T(); |
| } |
| #endregion |
| } |
I didn't send entire application because is huge... It's a portal with single page (default.aspx), with modules (custom controls) loadable at runtime.
If I remove url routing/rewriting everything works fine.
Thank you for your time!
PS: I saw a bug in code editor from current page:
I'm using Firefox (3.5.5) and if I'm trying to edit in code preview section using backspace the tab is closed.
I've done it 3 times till I understood to not use backspace... imagine :))
Cheers!