This is a migrated thread and some comments may be shown as answers.
Redirecting Parent From RadWindow Code Behind Issue
2 Answers 78 Views
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 16 Feb 2012, 08:04 PM
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;
        }    
</script>

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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 20 Feb 2012, 09:06 AM
Hello,

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

Thanks,
Princy.
0
Marin Bratanov
Telerik team
answered on 20 Feb 2012, 05:21 PM
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:  window.top.location.href = "yourUrl.aspx";



Regards,
Marin
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Asked by
Shawn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or