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

橙三吉。 提交于 2019-11-29 11:39:57

问题


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.


回答1:


I got it, its given in ScriptManager class itself.

System.Web.UI.ScriptManager.GetCurrent(this.Page);



回答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



回答3:


Have you checked out this:

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



来源:https://stackoverflow.com/questions/8601525/how-to-get-the-scriptmanager-of-master-page-into-child-pages-code-behind-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!