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
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();
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
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.
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
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.
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.
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!
I was trying to access this demo however, this isnt available.
Request you to repost it.
Many Thanks,
Ritika
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.
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!
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.
<a 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!
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.
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; |
} |
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.
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
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