How to open a RadWindow from code

7 posts, 1 answers
  1. Ed
    Ed avatar
    124 posts
    Member since:
    Jan 2008

    Posted 04 Nov 2009 Link to this post

    Hi there,

    Is it possible to open a RadWindow from server-side code instead of clicking on the element specified in the Window.OpenerElementID?  I need to load some data into the Session just before the window is opened, so that I can refer to it in the code-behind file of the window's destination page.

    Thanks,

    Ed Graham

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Nov 2009 Link to this post

    Hi Ed,

    Try the following code snippet which shows how to open RadWindow from code behind.

    cs:
        protected void Button1_Click(object sender, EventArgs e) 
        { 
            RadWindowManager windowManager = new RadWindowManager(); 
            RadWindow widnow1 = new RadWindow(); 
            // Set the window properties 
            widnow1.NavigateUrl = "Window1.aspx"
            widnow1.ID = "RadWindow1"
            widnow1.VisibleOnPageLoad = true// Set this property to True for showing window from code 
            windowManager.Windows.Add(widnow1); 
            this.form1.Controls.Add(widnow1); 
        } 

    You can also checkout the following documentation for more information:
    Setting Server-Side Properties

    -Shinu.
  3. Answer
    Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 05 Nov 2009 Link to this post

    Hello Ed,

    You can open the RadWindow from the server by setting its VisibleOnPageLoad property to true. More information on the subject is available here:
    http://www.telerik.com/help/aspnet-ajax/window_settingserversideproperties.html

    Best wishes,
    Georgi Tunev
    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.
  4. Ed
    Ed avatar
    124 posts
    Member since:
    Jan 2008

    Posted 05 Nov 2009 Link to this post

    Hi Shinu,

    Thanks for the reply.  Unfortunately, however, that didn't work for me; the window simply doesn't open.  I am calling the code from within a user control rather than a standard ASPX page, as follows:

    protected void lnkButton_Click(object sender, EventArgs e) 
        RadWindowManager windowManager = new RadWindowManager(); 
        RadWindow widnow1 = new RadWindow(); 
        // Set the window properties  
        widnow1.NavigateUrl = "http://www.google.co.uk/"
        widnow1.ID = "RadWindow1"
        widnow1.VisibleOnPageLoad = true// Set this property to True for showing window from code  
        windowManager.Windows.Add(widnow1); 
        this.Page.Controls.Add(widnow1); 

    Am I doing something wrong?

    Thanks for your help,

    Ed
  5. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 05 Nov 2009 Link to this post

    Hi Ed,

    The window must be added inside the form. The easiest way to achieve this is to put a standard asp:placeholder in that form and to add the window there. I also notice that in your code you create a window manager but you don't add it to the form as well.


    Best wishes,
    Georgi Tunev
    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.
  6. Ed
    Ed avatar
    124 posts
    Member since:
    Jan 2008

    Posted 05 Nov 2009 Link to this post

    Thanks Georgi -- that did the trick.
  7. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 05 Nov 2009 Link to this post

    Hi Ed,

    It is good to know that everything is working fine now. I just want to add something as I see that I missed it in my previous reply - sorry about that.
    Note that RadWindow can exist as a standalone control. This means that you can add it to the form, but you will not be able to use radopen() to open it - radopen(), radalert, radconfirm, radprompt, etc. functions belong to the RadWindowManager control.
    e.g.
    If you create a RadWindowManager and RadWindow controls and add the RadWindow to the RadWindowManager's Windows collection, if you add the RadWindowManager to the form, you will be able to open the newly created RadWindow by using radopen().

    If you create only RadWindow control and add it to the form, when you want to open it from the client, you should first get a reference to it and then call its show() method.
    for example:
    var oWnd = $find("<%= RadWindow1.ClientID %>");
    oWnd.show();



    Greetings,
    Georgi Tunev
    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