Following is the web site environment I created:
- I have a Master page.
- I have created a Child page from it.
- I have placed Script Manager on the Master page.
Now I want to access that Master page’s Script Manager to create a User Control dynamically in my code behind (C#) file.
How can I access Script Manager placed on master page to my child page.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I got it, its given in ScriptManager class itself.
System.Web.UI.ScriptManager.GetCurrent(this.Page);
Method 2
Not sure what exactly you want here… you want to access the script manager of your master page or just the masterpage?
You can access the master page by
Page.Master in code behind
Or
using System.Web.UI;
ScriptManager ScriptManager1 = (ScriptManager)Page.Master.FindControl("ScriptManager1")
// to access the script manager of master page
or
Page.Master.Controls.Add(Your UserControl object) // to add the user control in your master page
Method 3
Have you checked out this:
Working with ASP.NET Master Pages Programmatically
http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0