Add ScriptManager to Page Programmatically?

后端 未结 7 2154
夕颜
夕颜 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:14

    I used this code in custom web controls (.cs) that contain update panels.

    protected override void OnInit(EventArgs e)
    {
        //...
        if (ScriptManager.GetCurrent(this.Page) == null)
        {
            ScriptManager scriptManager = new ScriptManager();
            scriptManager.ID = "scriptManager_" + DateTime.Now.Ticks;
            Controls.AddAt(0, scriptManager);
        }
        //...
    }
    

提交回复
热议问题