Page.Error Handling within RadWindow

2 posts, 0 answers
  1. Billy
    Billy avatar
    5 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi,

    Can someone please tell me what is the best way to handle errors on a page displayed within a RadWindow?  I would like to handle the Page.Error event, but for some reason, this doesn't seem to fire when my page is displayed in a RadWindow.  I have also tried handle the ScriptManager.AsyncPostBackError event but it also doesn't seem to fire.  I can get the Application_Error to fire in Global.asax, but I can't get a reference to the Page to properly handle my errors from there.

    What I am trying to acheive is to have my error handler catch all AuthenticationExceptions and redirect to the login page.  However, if the page is actually a RadWindow, I don't want to redirect the RadWindow to the login page, I actually want to redirect the parent page to the login window.  I tried to use the Context.Handler from within Application_Error to determine the type of the page that caused the error, but this is null when the error is raised by a RadWindow, so I have no way to get a reference to the parent window to redirect it.  My solution was instead to have all pages that open in a RadWindow use a given MasterPage, and then handle the Page.Error event within the MasterPage, but unfortunately, this doesn't fire.  So I tried to handle it directly within the Page, but Page.Error doesn't seem to fire either.  Next I tried ScriptManager.AsyncPostBackError, but had no luck.  In every case, I manually listened to the event using eg. Page.Error += Page_Error;

    Any suggestions?

    Thanks,

    Billy

  2. Billy
    Billy avatar
    5 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Ok, I solved this one myself.  Still not sure why the Error events were not firing, but maybe it has something to do with the fact that they were occuring within the OnInit of the page???  Anyway, I ended up creating a generic javascript function that would redirect either the BrowserWindow of the RadWindow or the Window object regardless of what type of page was opened and I output this using Response.Write in Application_Error.   It works like a charm.

    Here's the code if anyone is interested:
    protected void Application_Error(object sender, EventArgs e) 
            { 
                var exception = Server.GetLastError(); 
                if (exception.GetBaseException() is AuthenticationException) 
                { 
                    var url = "logon.aspx?redirect=" + Request.Url.AbsoluteUri; 
                    Response.Write(string.Format( 
                        @"<script type='text/javascript'>
                            var oWindow = null;
                            if (window.radWindow)
                                oWindow = window.radWindow;
                            else if (window.frameElement != null && window.frameElement.radWindow)
                                oWindow = window.frameElement.radWindow;
                            if (oWindow != null)
                                oWindow.BrowserWindow.location='logon.aspx?redirect='+oWindow.BrowserWindow.location;
                            else window.location='{0}';
                        </script>",url)); 
                    Server.ClearError(); 
                } 
            } 

Back to Top