Adding ScriptManager to SharePoint WebPart
Posted by admin | Posted in Sharepoint | Posted on 31-01-2010-05-2008
0
Here is a sample source code on how to add ajax on sharepoint webpart.
using System.Web.UI;
…….
private ScriptManager ajaxManager;
……….
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!m_Error)
{
try
{
this.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
//prep ajax
this.ajaxManager = ScriptManager.GetCurrent(this.Page);
if (this.ajaxManager == null)
{
this.ajaxManager = new ScriptManager();
this.ajaxManager.EnablePartialRendering = true;
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ID, “_spOriginalFormAction = document.forms[0].action;”, true);
if (this.Page.Form != null)
{
string str = this.Page.Form.Attributes["onsubmit"];
if (!(string.IsNullOrEmpty(str) || (str != “return _spFormOnSubmitWrapper();”)))
{
this.Page.Form.Attributes["onsubmit"] = “_spFormOnSubmitWrapper();”;
}
this.Page.Form.Controls.AddAt(0, this.ajaxManager);
}
}
}
catch (Exception ex)
{
//
}
}
}






