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

Removing RadWindow from RadWindowManager on RadWindow Close

10 Answers 353 Views
Window
This is a migrated thread and some comments may be shown as answers.
Niels
Top achievements
Rank 1
Niels asked on 05 Oct 2010, 10:08 AM
How can I remove a RadWindow from it's RadWindowManager in client-side ? The problem is that I am using a RadWindow as a alert dialog which is created in server-side it's VisibleOnPageLoad = true and therefore on every postback the window keeps popping up. I would like to remove the window from the RadWindowManager when the user closes the RadWindow dialog but there is no client-side API for this. What is the standard way of removing RadWindow from RadWindowManager from the client-side ?

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Oct 2010, 10:42 AM
Hello,

One suggestion is adding the RadWindow controls directly in container control instead of adding to RadWindowManger window collection. The code got worked for me. Give a try with this.

Sample code:
protected void Button1_Click(object sender, EventArgs e)
{
    RadWindow newWindow = new RadWindow();
    newWindow.ID = "MyWindow";
    newWindow.VisibleOnPageLoad = true;
    newWindow.DestroyOnClose = true;
    this.form1.Controls.Add(newWindow);
}


Thanks,
Princy
0
Niels
Top achievements
Rank 1
answered on 05 Oct 2010, 11:30 AM
The problem is that I am using the RadWindowManager to close the RadWindow when the ok button is clicked, this is a onclientclick javascript function ('GetRadWindowManager().GetWindowByName("NameOfRadWindow").Close();return false;'), so not adding it to the RadWindowManager window collection is not an option. But as I understand there is no client side function for the removing of a RadWindow ? Or a client side function for setting the RadWindow's VisibleOnPageLoad to false ?
0
Georgi Tunev
Telerik team
answered on 08 Oct 2010, 09:12 AM
Hi Niels,

Try setting EnableViewState for the RadWindowManager to false. I assume that this is the reason for the problem as since Q3 2009, when a RadWindow is declared in  RadWindowManager it preserves its ViewState which was not so in previous versions. This leads to backwards incompatibility when the VisibleOnPageLoad property is used in this configuration with the idea to show the RadWindow only once.


Best wishes,
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
0
Aarsh
Top achievements
Rank 1
answered on 26 Jan 2013, 09:57 PM
Hi Georgi/Princy,

Is there a way to remove the window from the window manager ? Using client side script Or Server side ?

Below is the detailed description :

I am having a radWindow when user clicks on a radcontext-mentuitem bound with radtree.This radWindow works mostly like an dialogue or properties window in Microsoft Windows' explorer.The problem is, If I re-open the window it brings up two of those, which was easy to guess that the following C# code that I used, keeps on adding new windows for me and ShowOnLoad makes them all visible  - to which if I set to false, the dialogue box does not show up :

url ="some valid url";
RadWindow checkInOutPopUp = new RadWindow();
checkInOutPopUp.NavigateUrl = url;
checkInOutPopUp.VisibleOnPageLoad = true;
checkInOutPopUp.ID = "popUp";
checkInOutPopUp.Width = 600;
checkInOutPopUp.Title = title;
checkInOutPopUp.VisibleStatusbar = false;
checkInOutPopUp.EnableViewState = false;
checkInOutPopUp.Height = 300;
checkInOutPopUp.ClientIDMode = System.Web.UI.ClientIDMode.Static;
checkInOutPopUp.Behaviors = WindowBehaviors.Close;
checkInOutPopUp.DestroyOnClose = true;
checkInOutPopUp.EnableViewState = false;
checkInOutPopUp.Load += new EventHandler(checkInOutPopUp_Load);

BaseWindowManager.Windows.Add(checkInOutPopUp);

void checkInOutPopUp_Load(object sender, EventArgs e)
{
    RadWindow w = (RadWindow)sender;
    w.DestroyOnClose = true;
    w.Width = 600;
    w.Height = 300;
}


and to avoid that I digged up some server side event handler which actually can remove this window from window manager and it may solve my problem ( I needed to get this going quickly )

turned out, I could not find one event-handler for server side but I tried following with the client side event handler  checkInOutPopUp.OnClientClose :

function () {
    alert('Closing');
    var t_window = $find('" + checkInOutPopUp.ClientID + @"');
    if (t_window == undefined | t_window == null) {
        alert('t_window not found');
    }
    var t_windowmanager = $find('" + BaseWindowManager.ClientID + @"');
    if (t_windowmanager == undefined | t_windowmanager == null) {
        alert('t_window not found');
    }
    t_windowmanager.GetWindows();
    alert(t_windowmanager.length.toString());
    for (i = 0; i < t_windowmanager.length; i++) {
        alert(t_window.toString());
        if (t_window == t_windowmanager[i]) t_window.close();
    }

I get alert : "closing" and do not get "not found" in my case, which is a good thing that no literal is suffering from inanition ...  but certainly I can not figure out how can I remove that window.

I also tried :

for(i=0; i < t_windowmanager.length; i++) { alert(t_window.toString()); if(t_window == t_windowmanager[i]) remove(t_window);}}

w/o success.

I appreciate your concerns, in advance ...

Thanks
-Aarsh
0
Marin Bratanov
Telerik team
answered on 28 Jan 2013, 12:47 PM
Hi Aarsh,

There isn't such code on the client (apart from setting DestroyOnClose to true and closing the dialog), because such a change will not be reflected on the server. The manager is designed to allow for dynamic creation of RadWIndow instances on the client without the need for declaring their server objects, which is where such a discrepancy stems from.

On the server the Windows collection is exactly that - a simple collection, so you can traverse it and remove an element if you like.

The simplest logic I can suggest is using the approach from this sticky thread to open a dynamic instance on the client. It will be destroyed when the page is disposed and you can slightly modify it to use radopen() and take an argument for the URL. I also strongly advise against setting the ClientIDMode to static for RadControls, especially containers like RadWindow.

Removing a RadWindow instance from the client-side windows collection of a RadWIndowManager is, generally, not needed, and setting DestroyOnClose to true will do that for you. The initial fact remains that this will not reflect in the server collection with is explicitly persisted.

What is also important to note is, as Princy pointed out, that you can add the newly created on the srever RadWindow to a generic container that will not persist such dynamic controls across postbacks, instead of adding it to a manager's collection that will persist it. You can get a reference on the client to it by using its ClientID, not only through the manager.


Greetings,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Aarsh
Top achievements
Rank 1
answered on 28 Jan 2013, 02:16 PM
Hello Marin, thank you for your reply.

Per the sticky thread you mentioned, which seemed to be quite relevant to what I am looking for (thank you) I tried the suggested methodogy and also varified with dubgger; & JavaScript console :

I keep gettingthis error:
(function() {$find("PopUp").show();})();
"Unable to get value of the property 'show': object is null or undefined"

Please advise ...
0
Marin Bratanov
Telerik team
answered on 29 Jan 2013, 08:12 AM
Hello Aarsh,

The thread I linked shows that the Sys.Application.Load event should be used so the script is executed at the right time in order for $find() to actually return the desired reference instead of null. It also shows how the ClientID of the control is used to pass a correct argument to $find(). In your case it seems you are using neither, which results in the problem you are experiencing.


Kind regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Aarsh
Top achievements
Rank 1
answered on 29 Jan 2013, 02:31 PM
I am afraid that is not the case and I have had tried to follow the suggested scenario , but again please correct me if I am missing something :

The other problem I am having is the same window pops up regardless what menu item I click on ...

Code that executes when I click on a specific (not any) menu item ...
url = "some valid URL";
RadWindow checkInOutPopUp = new RadWindow();
checkInOutPopUp.NavigateUrl = url;
checkInOutPopUp.ID = "popUp";
checkInOutPopUp.Width = 600;
checkInOutPopUp.Title = title;
checkInOutPopUp.VisibleStatusbar = false;
checkInOutPopUp.Height = 300;
//checkInOutPopUp.Behaviors = WindowBehaviors.Close;
//checkInOutPopUp.OnClientClose =
// @"function() { alert ('Closing'); var t_window = $find('" + checkInOutPopUp.ClientID + @"'); if (t_window == undefined | t_window == null) {alert('t_window not found');} var t_windowmanager = $find('" + BaseWindowManager.ClientID + @"'); if (t_windowmanager == undefined | t_windowmanager == null) {alert('t_windowmanager not found');} t_windowmanager.GetWindows(); for(i=0; i < t_windowmanager.length; i++) { alert(t_window.toString()); if(t_window == t_windowmanager[i]) remove(t_window);}}";
checkInOutPopUp.DestroyOnClose = true;
checkInOutPopUp.EnableViewState = false;
checkInOutPopUp.Load += new EventHandler(checkInOutPopUp_Load);
string jScript = "function f(){if($find(\"" + checkInOutPopUp.ClientID + "\") != null && $find(\"" + checkInOutPopUp.ClientID + "\") != Undefined) $find(\"" + checkInOutPopUp.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", jScript, true);
checkInOutPopUp.VisibleOnPageLoad = true;
checkInOutPopUp.EnableViewState = false;
if (flag)
{
BaseWindowManager.Windows.Add(checkInOutPopUp);
BaseWindowManager.DataBind();
}
else
{
checkInOutPopUp.OnClientClose = "function() { var oWindow = radopen(\"" + url + ",\"" + title + ");}}";
}
return false;

0
Marin Bratanov
Telerik team
answered on 31 Jan 2013, 11:16 AM
Hi Aarsh,

Here is a list with the issue I can see in the below snippet:
- RadWindow renders entirely on the client, so its server Load event is merely inherited from  System.Web.UI.WebControls.WebControl. You do not need it and you should remove it.
- EnableViewState=false is set twice. Once should be enough. Moreover, since this is a dynamically created control it will be lost if a postback occurs and it is not recreated. Thus, if this code actually executes only when the desired item is clicked the window will be persisted, and lost otherwise (which, it seems, is the desired behavior)
- do not add that RadWindow to the manager's collection. If you do - it will be persisted regardless of the other settings you set, so VisibleOnPageLoad=true will remain in effect. This is the most likely reason for the behavior you are experiencing
- Since you set the VisibleOnPageLoad property you do not need to register the script. The two methods will do the same, so doubling the effort is not needed

All this being said - I believe code like this will work out:
RadWindow checkInOutPopUp = new RadWindow();
checkInOutPopUp.NavigateUrl = url;
checkInOutPopUp.ID = "popUp";
checkInOutPopUp.Width = 600;
checkInOutPopUp.Title = title;
checkInOutPopUp.VisibleStatusbar = false;
checkInOutPopUp.Height = 300;
checkInOutPopUp.DestroyOnClose = true;
checkInOutPopUp.EnableViewState = false;
checkInOutPopUp.VisibleOnPageLoad = true;
checkInOutPopUp.OnClientClose = "function() { var oWindow = radopen(\"" + url + ",\"" + title + ");}}";
someContainer.Controls.Add(checkInOutPopUp);

where someContainer is the container control where the window iwll be added to - it can be the form, it can be some panel, what is important is that it is part of the partial postback if you are using AJAX.

All the best,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Aarsh
Top achievements
Rank 1
answered on 12 Feb 2013, 08:49 PM
Thanks Marin, your last post certainly helped me. I ended up using the code snippet below.

public bool NewModelWindow(string url, bool flag, RadWindowManager WindowManagerID, string title = "", string openerId = "")
        {
            url = IconSoftware.IconUser.GetFullApplicationPath() + url;
            RadWindow checkInOutPopUp = new RadWindow();
            checkInOutPopUp.NavigateUrl = url;
            checkInOutPopUp.ID = "popUp";
            checkInOutPopUp.Width = 675;
            checkInOutPopUp.Title = title;
            checkInOutPopUp.VisibleStatusbar = false;
            checkInOutPopUp.Height = 600;
            checkInOutPopUp.DestroyOnClose = true;
            checkInOutPopUp.EnableViewState = false;
            checkInOutPopUp.Load += new EventHandler(checkInOutPopUp_Load);
            string jScript =
@"function f(){
    if($find(\"" + checkInOutPopUp.ClientID + "\") != null && $find(\"" + checkInOutPopUp.ClientID + "\") != Undefined) $
          find(\"" + checkInOutPopUp.ClientID + "\").show();
          Sys.Application.remove_load(f);
     }
     Sys.Application.add_load(f);"
 ;
     ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", jScript, true);
     checkInOutPopUp.VisibleOnPageLoad = true;
     checkInOutPopUp.EnableViewState = false;
     if (flag)
     {
          WindowManagerID.Windows.Add(checkInOutPopUp);
          WindowManagerID.DataBind();
     }
      else
     {
           checkInOutPopUp.OnClientClose = "function() { var oWindow = radopen(\"" + url + ",\"" + title + ");}}";
     }
    return false;
}
Tags
Window
Asked by
Niels
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Niels
Top achievements
Rank 1
Georgi Tunev
Telerik team
Aarsh
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or