Duplicate Script Managers

297 Views Asked by At

I'm working on an ASP.Net webforms app, and I've run into a unique issue. There is a script manager for an update panel on the MasterPage, as well as a script manager in a sub-page calling the master page. This as i'm sure you will note cause an exception to be thrown and crash the webapp.

I've tried programatically excluding the scriptmanager + update panel from the code as follows:

<% If Not (Result.RawURL.Contains("ExcludedPageDirectory") Then %>
<!-- all that code goes here -->
<% End If%>

However I think just the presence of the script manager tag in the source is causing the error. How would I programatically handle this?

3

There are 3 best solutions below

1
On BEST ANSWER

A page can contain only one ScriptManager control in its hierarchy. To register services and scripts for nested pages, user controls, or components when the parent page already has a ScriptManager control, use the ScriptManagerProxy control (Source: MSDN)

1
On

You don't require a script manager again in the page if you have it in the master page. Remove it and try

0
On

I ended up duplicating the master page and left out the update panel/scriptmanager code. This seems to have been the most elegant solution for the given situation. However I feel that the ScriptManagerProxy answer held the best possible solution had the duplication of the masterpage not been possible.