Add ScriptManager to Page Programmatically?

后端 未结 7 2039
夕颜
夕颜 2020-12-13 00:30

I am developing a WebPart (it will be used in a SharePoint environment, although it does not use the Object Model) that I want to expose AJAX functionality in. Because of t

7条回答
  •  囚心锁ツ
    2020-12-13 01:34

    I had the same basic issue the rest of you had. I was creating a custom ascx control and wanted to be able to not worry about whether or not the calling page had the scriptmanager declared. I got around the issues by adding the following to the ascx contorl itself.

    to the ascx page -

    in the update panel itself - oninit="updatePanel1_Init"

    to the ascx.cs file -

    protected void updatePanel1_Init(object sender, EventArgs e)
    {
         if (ScriptManager.GetCurrent(this.Page) == null)
         {
             ScriptManager sManager = new ScriptManager();
             sManager.ID = "sManager_" + DateTime.Now.Ticks;
             phScriptManager.Controls.AddAt(0, sManager);
         }
    }
    

    Thank you to everyone else in this thread who got me started.

提交回复
热议问题