RadWindow from server

3 posts, 0 answers
  1. Naupad
    Naupad avatar
    23 posts
    Member since:
    Dec 2011

    Posted 16 Feb 2012 Link to this post

    I have this function on my aspx page.
    function openWindow() {
              
                //get a reference to the window
                var oWnd = $find("<%= RadWindow2.ClientID %>");
                //set its NavigateUrl
                oWnd.setUrl("http://xyz.com/abc.zip");
                //add the name of the function to be executed when RadWindow is closed
                
                //show the window
                oWnd.show();
            }

    I want to call this function in Button click event through RegisterStartupScript. It gets called but window doesn't open. Also I want to open a url which has a zip file for download. So as soon as user is prompted about Save dialog box, I want to close radwindow.

    HELP!!!!!
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2012 Link to this post

    Hello,

    Try the following code to open RadWindow through RegisterStartupScript.
    C#:
    protected void Button1_Click(object sender, EventArgs e)
      {
        string openWindowScript = "<script language='javascript'>function f(){openWindow(); Sys.Application.remove_load(f) ;}; Sys.Application.add_load(f)  ;</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", openWindowScript);
      }

    Thanks,
    Princy.
  3. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 17 Feb 2012 Link to this post

    Hi guys,

     I suggest to improve the sample code Princy provided in the following manner:

    1) Use ScriptManager instead of ClientScript - this will handle more scenarios, e.g when an AJAX request was made.

    2) Since your js function already has a name, it is not needed to wrap it the additional named f function.

    With the above your code will look like the following:

    js in aspx:

    function openWindow() {
               Sys.Application.remove_load(openWindow);
                 //get a reference to the window
                 var oWnd = $find("<%= RadWindow2.ClientID %>");
                 //set its NavigateUrl
                 oWnd.setUrl("http://xyz.com/abc.zip");
                 //add the name of the function to be executed when RadWindow is closed
                  
                 //show the window
                 oWnd.show();
             }

    code-behind:

    protected void Button1_Click(object sender, EventArgs e)
      
      {
      
     
     ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "Sys.Application.add_load(openWindow)" , true);
      
      }


    You can find a more detailed article about opening RadWindow from the server below:

    http://www.telerik.com/help/aspnet-ajax/radwindow-troubleshooting-opening-from-server.html

    I hope that my reply is helpful, let me know how it goes.

    Kind regards,
    Svetlina Anati
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top