Redirecting Parent From RadWindow Code Behind Issue

3 posts, 0 answers
  1. Shawn
    Shawn avatar
    83 posts
    Member since:
    Jan 2009

    Posted 16 Feb 2012 Link to this post

    I am having a hell of a time getting this to work correctly.  I have a RadWindow that can be launched from any site on the page (the link resides on a master page) and will bring up a login window.

    When the user successfully logins in, the SQL reader will set a variable in session and then once the data reader has closed SHOULD redirect to a page based on what is stored in the session variable.

    So I need to be able in my code behind to say If Session("ThisValue") = Something then Close RadWindow and redirect parent.

    I have this code in the RadWindow:
        <script type="text/javascript">
            function RedirectUser(sender, args) {
                GetRadWindow().BrowserWindow.location.href = '../ThisPageWhenRedirectUser.aspx';
                GetRadWindow().close();       //closes the window    
            function GetRadWindow()   //Get reference to window 
                var oWindow = null;
                if (window.radWindow)
                    oWindow = window.radWindow;
                else if (window.frameElement.radWindow)
                    oWindow = window.frameElement.radWindow;
                return oWindow;

    I just don't know how to call that from my code behind.  I am trying it like so:

    'after database has retrieved and stored the value in session
    If (Session("UserType") = Something Then CloseRadAndRedirect()
    Public Sub CloseRadAndRedirect()
            If (Not ClientScript.IsStartupScriptRegistered("GetRadWindow")) Then
                ScriptManager.RegisterStartupScript(Page, Me.GetType(), "GetRadWindow", "RedirectUser();", True)
            End If
        End Sub

    This does not work.  In fact it simply refreshes the radwindow and the controls lose their formatting and styles.

    Any help would be greatly appreciated.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Feb 2012 Link to this post


    One suggestion is you can try to close the RadWindow on client side and redirect to the parent page as shown using RadAjaxManager.
    function windowclose()
         var win = $find("<%= RadWindow1.ClientID %>");
         var mngr = $find("<%= radajaxmngr.ClientID %>");
    protected void radajaxmngr_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
           if ( Session["temp"]==" ")// check your condition here

  3. Marin Bratanov
    Marin Bratanov avatar
    5922 posts

    Posted 20 Feb 2012 Link to this post

    Hi Shawn,

    The first thing I notice in your snippet is that it calls the RedirectUser() function, while in your JavaScript it does not exist, you have RedirectUser() instead. Also, the call to check if the script is registered is not necessary and it may not even be entering the body of the if statement in your case. You can also examine this help article on calling a JavaScript function from the server. Please also make sure you do not have some JavaScript error on the page and if so - resolve it first. Alternatively, you may simply redirect the topmost frame without ever referencing the RadWindow with the following simple line: = "yourUrl.aspx";

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top