Reputation: 1154
So basically, I have a master page and hundreds of content pages. Every content page contains ToolKitScriptManager
. Right now, I want to add ScriptManager
on the master page and when I try to execute, error shows "Only one instance of a ScriptManager can be added to the page."
I know that I have to comment/remove every ToolKitScriptManager
line on each content page. But for some reason, I can't edit hundreds of content pages just to remove those ToolkitScriptManager
code.
What I want to ask, is there any solution so I can disable ToolkitScriptManager
(on content page) from master page's behind code programmatically so I don't have to edit my hundreds of content pages?
EDIT:
From this answer's question: How to use AJAX in master page when content pages have ScriptManager? , there are 3 ways he could give. The last way is impossible because I still have to edit the content pages. However, I don't get what he wrote about the first and second way. If I have to wrap Content Page's ToolKitScriptManager
with this:
<asp:ContentPlaceHolder ID="PlaceHolderID" runat="server" >>
</asp:ContentPlaceHolder>
then the Master Page's ScriptManager
will override the Content Page's ToolKitScriptManager
. Correct me if I was wrong. And if I was right, the first/second way is also impossible because still have to edit the content pages, right?
Upvotes: 1
Views: 1783
Reputation: 7473
in your master page, handle your script manager's on Init and remove the toolkit script managers from the content page each time your master page's script manager loads:
MasterPage ASPX:
<asp:ScriptManager ID="ScriptManager1" runat="server" OnInit="ScriptManager1_Init"></asp:ScriptManager>
MasterPage Code Behind:
protected void ScriptManager1_Init(object sender, EventArgs e)
{
try
{
foreach (Control _ctrl in ContentPlaceHolder1.Controls)
{
if (_ctrl.GetType() == typeof(AjaxControlToolkit.ToolkitScriptManager))
{
ContentPlaceHolder1.Controls.Remove(_ctrl);
break;
};
}
}
catch (Exception ex)
{
}
}
Upvotes: 3