How to close the Window within ASP.Net

4 posts, 0 answers
  1. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 04 Nov 2009 Link to this post

    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:
  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 10 Nov 2009 Link to this post

    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.
  3. DevCraft banner
  4. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 10 Nov 2009 Link to this post

    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.
  5. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 13 Nov 2009 Link to this post

    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.
Back to Top