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

Multiple WindowManager controls duplicates Javascript

6 Answers 101 Views
Window
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 2
Keith asked on 07 Jun 2013, 03:54 AM

I am working on breaking down very complex aspx files into smaller more manageable chunks by breaking out duplicated sections of code. So far this has worked out well, however, in some instances, the resulting control requires a window manager. This isn't a problem until more than one control is used that requires a window manager.

However, when including more than one control, a window manager is created for each control. Again, this isn't a huge problem, except that it duplicates javascript functions on the page so that there are multiple functions with the same name and code, for example

function RadWindowprompt_detectenter(id, ev, input)

This isn't my code, but code injected into the resulting html page to handle events for the radwindows.

Is the only solution to place a single windowmanager in the master page and then try and find it in the codebehind and then edit it programmatically to add window templates as needed?

I'd like to remove the duplicates because additional window managers simply add more overhead to the page.

I'll entertain any ideas to make it more efficient.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jun 2013, 05:01 AM
Hi,

Instead of using multiple RadWindowManager, I would suggest not to use radopen but to get a reference to the desired window by using $find() and then to call its show() method.

 When having multiple managers on the same page, you need to have in mind the following:
  1. GetRadWindowManager, radopen, radalert, radconfirm and radprompt functions always use the RadWindowManager that is first rendered on the page.
  2. Every RadWindowManager "knows" about the RadWindows that are declared in its Windows collection only. If you use radopen and the RadWindow that you want to open is not in the first RadWindowManager, this manager will create a new RadWindow.


Thanks,
Shinu.
0
Keith
Top achievements
Rank 2
answered on 07 Jun 2013, 01:33 PM
All of the windows I use are opened using their respective show methods, so that isn't a problem. The biggest problem is the extra code that is loaded into the page because of the multiple managers.

I don't want to use multiple managers, but it is the only way I can include resources needed for the controls only when the specific control is loaded. i.e. WindowA is used by ControlA WindowB is used by ControlB, so if I have a page that only has ControlA or ControlB everything is fine, however, if I have a page that uses ControlA and ControlB or multiples of either, RadWindowManager controls are created for every control.

Because I am using a template for these windows, not only are there unused managers, but also unused templates and javascript.
0
Marin Bratanov
Telerik team
answered on 11 Jun 2013, 01:07 PM
Hello Keith,

By design a RadWindowManager is a singleton, meaning that it expects to be the only one on the rendered page. This is why the scripts are included in the PromptTemplate for each template. I am logging the idea that this function should be in the RadWindowManager scripts file instead of the template, so our developers can review it. You can monitor, comment and vote on it to raise its priority here. I have also updated your Telerik points for your suggestion.

This is not a lot of code and by using the approach Shinu quoted from this help article should allow you to show the desired template from the desired control.

An alternative you can look into is this KB article. You can create a public property in the master page that will return the RadWnidowManager there so its templates can be changed as needed. This can work if you do not need two different templates at once on a given page+master page combination. If you do - having several managers is the only option that requires little code. An lternative could be creating custom RadWindow dialogs whose ContentTemplate will resemble the desired dialog template and they will have the settings you desire (an example of such a dialog is shown here, see the last section).


Regards,
Marin Bratanov
Telerik
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 the blog feed now.
0
Keith
Top achievements
Rank 2
answered on 11 Jun 2013, 07:48 PM
Thanks for logging this idea to move the scripts to the script manager.

In the meantime, I am having some difficulty removing the duplicted code from multiple controls.

In one example alone, I am using 17 user controls on a single page. The user control uses a RadWindowManager with a templated window (instead of using an external linked aspx page). This results in 17 RadWindowManager objects on the page. Because all of the templates are identical, it doesn't really matter which template is used, but the extra overhead bloats what should be a small page into something much larger.

In my codebehind, I tried to target a RadWindowManager on the parent page and create a RadWindowTemplate for it while removing the RadWindowManager from the control. I spent several days with different permutations and finally gave up after never being able to get it to work correctly.

My steps were:
1) find the RadWindowManager on the parent page;
2) create a new RadWindowTemplate from an html literal;
3) find the RadScriptManager on the parent page;
4) add my javascript to the script manager;

The problem is that the controls in the template could not be found by the javascript to edit the values as needed .. or at least I couldn't get it to work.

I think the problem was with the template definition, but I don't know for sure.

Anyway, I'd still entertain adding a template to the window manager on the parent page if I could figure out how to do it correctly and get it to work  ... but the documentation isn't clear on how to do this properly.
 
0
Accepted
Marin Bratanov
Telerik team
answered on 14 Jun 2013, 01:44 PM
Hello Keith,

I may have misunterstood your case a bit. I was referring to using the predefined dialogs: http://demos.telerik.com/aspnet-ajax/window/examples/browserdialogboxes/defaultcs.aspx.

If you are using the ContentTemplate of a single RadWindow (http://demos.telerik.com/aspnet-ajax/window/examples/internalcontent/defaultcs.aspx) I would advise the following
  • move this RadWindow out of the RadWindowManager, because:
    • it does not require a manager to work properly in the first place, thus less instances will be created
    • it is not recommended to use the ContentTemplate of a RadWindow inside the Windows collection of a RadWindowManager
  • remove all unnecessary RadWindowManager and use the $find().show() approach to show your standalone RadWindows. If you need more than one RadAlert/RadConfirm/RadPrompt template – use the approach I outlined in my previous reply (i.e. only have as many as needed, declared on a common page, not in separate user controls)
  • use the approach from this KB article to create separate function that can be used inside the context of a separate user control instance


Regards,
Marin Bratanov
Telerik
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 the blog feed now.
0
Keith
Top achievements
Rank 2
answered on 14 Jun 2013, 02:53 PM
This resolves the issue with the RadWindowManager injecting extra javascript.

I presume I can iterate through my controls in the codebehind and set the visibility of the extra RadWindow objects to false, thus removing the extra windows from the rendered page. 
Tags
Window
Asked by
Keith
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Keith
Top achievements
Rank 2
Marin Bratanov
Telerik team
Share this question
or