How to get the ScriptManager of Master Page into Child page's code behind c# (.cs) file
Asked Answered
D

3

20

Following is the web site environment I created:

  1. I have a Master page.
  2. I have created a Child page from it.
  3. 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.

Dereism answered 22/12, 2011 at 9:4 Comment(2)
Why do you need to access the ScriptManager to create a control?Danielson
I want to create UpdatePanel dynamically , so I need script manager too.Dereism
D
54

I got it, its given in ScriptManager class itself.

System.Web.UI.ScriptManager.GetCurrent(this.Page);
Dereism answered 19/9, 2012 at 7:32 Comment(2)
How to set the property of that script manager. I am getting an error when trying to set EnablePartialRendering to falseCaste
if it resolved your problem, please consider giving +1 to question and answer both.\Dereism
G
6

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
Gliadin answered 22/12, 2011 at 9:8 Comment(2)
ScriptManager sm = (ScriptManager)Page.Master.FindControl("ScriptManager1");Gliadin
I already got the answer i.e. ScriptManager.GetCurrent(this.Page), your answer is right too.Dereism
P
1

Have you checked out this:

Working with ASP.NET Master Pages Programmatically
http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx

Phi answered 22/12, 2011 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.