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

How to close the Window within ASP.Net

3 Answers 57 Views
Window
This is a migrated thread and some comments may be shown as answers.
Hector
Top achievements
Rank 1
Hector asked on 04 Nov 2009, 11:56 PM
Is there a way to close the Rad Window from Asp.Net code?  I have an RadHTMLPlaceHolder inside of a window and where I load a webpage to export a report.  Once it is done exporting, I need it to automatically close the Rad Window.  I tried adding closing it through JavaScript, but it closes the window to the Silverlight app.  I found an article on accessing managed code through Asp.Net and from JavaScript, and this seems it would work, however, because the page that I am loading inside the RadWindow does not have the Silverlight control on it, I cannot call the code.  Is there any way to do this?

Here is the article I found to calle SL managed code from asp:

3 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 10 Nov 2009, 08:52 AM
Hello Hector,

You are correct when telling us your suggestion. The only possible technics to establish a communication between Silverlight page and asp.net is by using some web service or javascript. Let us know if you need any further assistance. 

All the best,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hector
Top achievements
Rank 1
answered on 10 Nov 2009, 01:17 PM
I forgot to updated this post.  I found a solution right here on Telerik for the HTMLPlaceHolder.... Accessing Managed Code.
Here is what I have done.

(SilverlightTestPage.aspx) Silverlight ASPX page; added a JavaScript handler to accessing the Silverlight object:
<head runat="server">  
    <title></title>  
     
    <script type="text/javascript">  
         
        /********* Access to the SilverLight app **********/  
        function GetSilverlightApplication() {  
            return document.getElementById("Xaml1");  
        }  
    </script> 
</head> 

On the Page.xaml, I added a Scriptable fuction to be able to be called from JS code later;
        public Page()  
        {  
            HtmlPage.RegisterScriptableObject("MySilverlightPage", this);  
        }  
 
        [ScriptableMember]  
        public void CloseRadWindow()  
        {  
            this.RadWindow1.Close();  
        } 

And now, to initiate the call to close window from the ASPX source page on the HTMLPlaceHolder that points to a different page than that of the one that holds the Silverlight control (anotherpage.aspx.cs):
string strScript = "<script language=javascript>CloseSLWindow();</script>";  
// Try to close the window  
if(!ClientScript.IsStartupScriptRegistered("clientScript"))  
{  
     ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", strScript);  

Finally, on the other page aspx (anotherpage.aspx), we get access to the silverlight application throught the JS we did on the silverlight page.  Once we have access to the SL control, we can call the codebehind function we decorated with [ScriptableMember] tag.
 
<script type="text/javascript" language="JavaScript1.2">      
     function CloseSLWindow()   
     {  
         var silverlightApplication = parent.GetSilverlightApplication();  
         silverlightApplication.Content.MySilverlightPage.CloseRadWindow();  
     }  
 
</script> 

You can use this same method for performing any function on silverlight, but initiated through the aspx page.  For example, I made another function to display messages in SL:

[ScriptableMember]  
public void ShowMessage(string message)  
{  
   Telerik.Windows.Controls.RadWindow.Alert(message);  
Thanks.
0
Kaloyan
Telerik team
answered on 13 Nov 2009, 01:04 PM
Hello Hector,

Thank you very much for sharing your experience with us. This is a useful technique that will be of help for a lot of people.

Best wishes,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Window
Asked by
Hector
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Hector
Top achievements
Rank 1
Share this question
or