This is a migrated thread and some comments may be shown as answers.

RadWindow CLose

18 Answers 836 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mahakar
Top achievements
Rank 1
Mahakar asked on 20 Sep 2008, 08:52 AM
Hi  Al,

I am using a RadWindow inside a RadWindowManager with version Q2 2008.
 
I am opening an .aspx page using this rad window. NOw I have a close button on the .aspx page which is opened using this rad window.

I want to close this window using this close button.

PLease suggest.

18 Answers, 1 is accepted

Sort by
0
Accepted
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 22 Sep 2008, 09:30 AM
A simple example which illustrates how to close a window from a button which is in the window is available here:
http://demos.telerik.com/ASPNET/Prometheus/Window/Examples/CommunicationBetweenRadWindows/DefaultCS.aspx

e.g. all you need to use is the following JavaScript code(from the example above):
----------------------------------------
function
GetRadWindow()
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;

else
if (window.frameElement.radWindow)
 oWindow = window.frameElement.radWindow;

return oWindow;
}
----------------------
//get a reference to the RadWindow
var oWnd = GetRadWindow();
//close the RadWindow
oWnd.close();

0
Mahakar
Top achievements
Rank 1
answered on 25 Sep 2008, 04:26 AM
Thanks for solution
0
Craig
Top achievements
Rank 1
answered on 28 Sep 2008, 03:53 AM
This works for me but I have a more complex situation. I want to use the RadWindow as my login window.

Example: I'm on Page1.aspx and click the login button which brings up my RadWindow. The values from the login control on the RadWindow are used to authenticate the user. Once authenticated, however, I'd like to automatically close the RadWindow and redirect to Page2.aspx. This does not work for me using this code.

I can have the window close on the click of the button, but not with any authentication.Or I can have it authenticate but Page2.aspx shows up in my RadWindow.

I've RT(F)M but can't seem to find an answer. Any help would be greatly appreciated.

Thanks,
Craig
0
Georgi Tunev
Telerik team
answered on 28 Sep 2008, 12:57 PM
Hello Craig,

I believe that the following forum thread will be of help:
http://www.telerik.com/community/forums/thread/b311D-bgbcth.aspx



Sincerely yours,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Elango
Top achievements
Rank 1
answered on 05 Mar 2009, 06:24 PM
Hi Georgi,
       Same like Crai i also having the same issue with login controls and you solution is not working for me. I have a page and login link which opens Radwindow dialog box in which login.aspx page is loaded. I am using asp.net login built in controls. I don't have any asp buttons to login. These login controls automatically comes with Login button. I have OnAuthenticate event. In which i am trying check the user validity. Below is the code :

protected

 

void OnAuthenticate(object sender, AuthenticateEventArgs e)

 

{

 

if (Login1.UserName == "elango" && Login1.Password == "elango")

 

{

 

    e.Authenticated =

true;

 

 

 

    label1.Text = "<script type='text/javascript'>top.location.href='MainPage.aspx';GetRadWindow().Close();</script>";

 

 

 

}

 

 

else

 

{
    // To do

 

}

}

The above label1.text script injection is suggested for one telerik issues to close the radwindow. I guess this solution shud work if it is asp:button doing our custom authentication. But here as it is not that case. Please let me know how to solve this issue.

Regards,
Elango

0
Georgi Tunev
Telerik team
answered on 06 Mar 2009, 09:06 AM
Hi Elango,

The reason for the problem is actually not in the RadWindow control, but in the way the asp:login control works.

Asp:login by design will redirect the user upon successful login to another page that is defined in the web.config or with the DestinationPageURL property. If none of these settings is configured, it actually loads the same page again. More information on the subject is available in MSDN and other resources like this one for example.

Basically, what happens is that the script is inserted correctly on the page, but the login control reloads it so there is no effect from the script. You can test this for yourself by setting the Text property of the label to some string - you will not see it on the page after logging in.

Since the login control redirects the page, it will be shown in the RadWindow itself - our control is basically an IFRAME and behaves just like one. I assume you don't want that, so I suggest to put the following script in the page to which you intend to redirect your users after successful login:

if (window != window.top) window.top.location.href = window.location.href; 

The logic behind it is simple - if this page is not displayed as a topmost page (e.g directly in the browser) but in some container (like IFRAME / RadWindow /etc.), load it as topmost page.


Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Princy Verma
Top achievements
Rank 1
answered on 16 Feb 2010, 11:04 AM
Hi Georgi,

I am facing the same issue and not able to rectify it.
I am using a asp:Login control in a rad window for user login
I have following .aspx code(JavaScript) to close the rad window :

  <script type="text/javascript">
    function GetRadWindow() 
    {  
        var oWindow = null;        
        if (window.radWindow) oWindow = window.radWindow;   
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;   
        return oWindow;  
    } 
    </script>

and in .cs file on a button click event(I am calling this event in "LoggedIn" property of asp:Login control) I have following code : 
Page.RegisterStartupScript("closeWindow", "<script type='text/javascript'>GetRadWindow().close()</script>");

The issue is this, rad window doesn't get close and also the parent page is not refreshed.Whereas, if I press F5 the window disappears and the parent page shows the logged in page.
Please help to sort this issue ASAP.

Cheers,
Princy
0
Georgi Tunev
Telerik team
answered on 18 Feb 2010, 12:35 PM
Hi Princy,

Please make sure that the JavaScript is actually called - instead of calling GetRadWindow().close(), call a simple alert() and see if it fires. Once the alert is successfully fired on the client, the code that closes RadWindow will work as well.


Kind regards,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gilbert
Top achievements
Rank 1
answered on 11 Mar 2010, 12:36 AM

Hi,

I'm having trouble with the GetRadWindow() function posted above. It seems that window.frameElement returns null so calling window.frameElement.radWindow returns a null reference exception. I did alerts in the method and everything looks fine until that point. How do I fix this?

The Close button is inside the RadWindow. When clicked there is some server side processing done and afterward I call   

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "CloseWindow""CloseWindow();"true); 

to try and close it. That's when I get the javascript exception.
 

<telerik:RadWindow ID="RadWindow1" runat="server" Modal="True" Width="1000px" Height="660px" 
    OpenerElementID="aLoadTestData" AutoSize="false" Skin="Office2007" Animation="None" 
    Behaviors="Move,Close" KeepInScreenBounds="false">  
    <ContentTemplate> 
        <asp:UpdatePanel runat="server" ID="updatepanel">  
            <ContentTemplate> 
 
                <script language="javascript" type="text/javascript">  
                    function GetRadWindow() {  
                        if (window.radWindow) oWindow = window.radWindow;  
                        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;  
                        return oWindow;  
                    }  
                    function CloseWindow() {  
                        var oWindow = GetRadWindow();  
                        oWindow.Close();  
                    }      
                </script> 
        ...       
        ...  
        ...  
                <div id="buttons" style="text-align: right; padding: 15px 15px 0px 0px;">  
                    <asp:Button ID="Close" runat="server" Text="Load" OnClick="SomeFunction" 
                        Visible="false" /> 
                </div> 
            </ContentTemplate> 
        </asp:UpdatePanel> 
        <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="updatepanel" runat="server">  
            <ProgressTemplate> 
                <asp:Panel ID="Panel1" CssClass="overlayModal" runat="server">  
                    <asp:Panel ID="Panel2" CssClass="loaderModal" runat="server">  
                        <img alt="Loading..." src="/images/ajax-loader.gif" /> 
                    </asp:Panel> 
                </asp:Panel> 
            </ProgressTemplate> 
        </asp:UpdateProgress> 
    </ContentTemplate> 
</telerik:RadWindow> 

Thanks!
0
Ritika Gupta
Top achievements
Rank 1
answered on 11 Mar 2010, 08:24 AM
Hi,

I was trying to access this demo however, this isnt available.

Request you to repost it.

Many Thanks,
Ritika
0
Georgi Tunev
Telerik team
answered on 11 Mar 2010, 08:35 AM
Hi Gilbert,

The GetRadWindow() function is used to get a reference to the RadWindow object when called from within a content page. In your case however, you are using RadWindow as a controls' container - e.g. the content is on the same page. In such scenario, you should get a reference to the RadWindow by using $find() and then call its close() method.

Kind regards,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gilbert
Top achievements
Rank 1
answered on 11 Mar 2010, 03:58 PM
Thanks Georgi, it worked like a charm!

So $find is to fetch the RadWindow container for controls inside and GetRadWindow() is to get the RadWindow object reference from the content page. Gotcha!
0
Gilbert
Top achievements
Rank 1
answered on 11 Mar 2010, 09:53 PM
Hi Georgi,

After trying out the close a little more it seems that when I reopen the RadWindow the old content it still there. It's especially bad because the UpdateProgress seems to be still loading and so nothing can be done in the window. I thought setting DestroyOnClose will destroy the window and a new window with new state will appear if I reopen it. I also tried to dispose the Window before closing but it doesnt' work either. I'm trying to get a new RadWindow without having to postback when clicking an open link.

So a summary of what I'm doing right now is

-I have an anchor that is referenced by the RadWindow OpenerElementID so it opens client side.
<href="#" id="aLoadTestData">Load test data</a>   

-Hitting the Load button in the RadWindow will do some server-side processing and then call the javascript to close the window.
-Trying to reopen the window I still see the old content when I want a complete new state. DestroyOnClose and dispose isn't working either.

Thanks!
0
Georgi Tunev
Telerik team
answered on 16 Mar 2010, 02:43 PM
Hi Gilbert,

The behavior that you experience is expected - in your case, RadWindow behaves just like a standard iNaming container. You need to manually clear the controls in the container after your server-side code is done and before outputting the code that would close the RadWindow.


Regards,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Lester
Top achievements
Rank 1
answered on 26 Mar 2010, 06:25 PM
Hello.

I am trying to use your sample for closing a radwindow from inside using javascript. But the getradwindows function fails cause firefox stop it with the following error

Error: Permission denied for <http://xxxxxxxxxxx> to get property HTMLIFrameElement.radWindow from <http://yyyyyyyy.com>.
Source File: http://xxxxxxxxxxxxxxx/upload.aspx?f=TgAzAHQAcgAwAEMANABwADYAdABDADoAXABjAGwAaQBlAG4AdABzAFwAYQBwAHAAbABpAGMAYQB0AGkAbwBuAHMAXAA3ADQAZAA3ADgANABhAGUALQBkADMANABkAC0ANABiAGQAMQAtADkAMABmADQALQA4ADcAMQBmADMAZAAyAGUANgBjADMAYwBcAFwA&RadUrid=551a0eb1-6b23-4eda-91ff-6088960df1cc
Line: 15

the line where it fails is:

function GetRadWindow() 
        { 
            var oWindow = null
            if (window.radWindow) oWindow = window.radWindow; 
 
            else if (window.frameElement.radWindow) <<<-------------------- Here fails the execution
             oWindow = window.frameElement.radWindow; 
 
            return oWindow; 
        } 
 
0
Georgi Tunev
Telerik team
answered on 29 Mar 2010, 03:04 PM
Hi Lester,

If the content page is from another domain, this behavior is expected. The browser's security mechanism will not allow you to get access to an object in the other page (the RadWindow object in your case). There is no workaround for this issue - otherwise it would be a major security hole.

All the best,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gregg
Top achievements
Rank 1
answered on 27 Aug 2013, 05:44 PM
Hi Georgi,

I have an asp.Login control on a page running in a RadWindow.  I am using your suggested script to load the destination page as the topmost page when the asp.Login control redirects to a new page after a successful login:

if (window != window.top) window.top.location.href = window.location.href;

This script causes the page to load twice, first in the RadWindow and then again in the top window.  Is there a way to call this script before the page gets rendered in the RadWindow?

Thank you,
Gregg
0
Marin Bratanov
Telerik team
answered on 28 Aug 2013, 11:21 AM
Hello Gregg,

There is no way to do this. A page, while, rendering on the server, cannot know that it is in an iframe in order to take any action. Even if it did - it cannot know what the parent page is, or access it in order to redirect the browser itself. This means that only a similar frame-buster script (or other logic like an anchor with target="_top" clicked programmatically) can redirect the main browser window and you will always have two login page loads.


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Window
Asked by
Mahakar
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Mahakar
Top achievements
Rank 1
Craig
Top achievements
Rank 1
Georgi Tunev
Telerik team
Elango
Top achievements
Rank 1
Princy Verma
Top achievements
Rank 1
Gilbert
Top achievements
Rank 1
Ritika Gupta
Top achievements
Rank 1
Lester
Top achievements
Rank 1
Gregg
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or