Tuesday, December 30, 2008

Changes made to deploy ASP.NET 2.0 AJAX 1.0 control in MOSS 2007 application

- Downloaded ASP.NET 2.0 AJAX 1.0 extentions from http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&DisplayLang=en

- Downloaded ajax.config feature and from http://www.codeplex.com/features/Release/ProjectReleases.aspx?ReleaseId=2502

added and deployed wsp and activated ajax.config feature on necessary web application.


-Made a web part

using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace CompanyName
{
[XmlRoot(Namespace = WebPartConstants.WEBPART_NAMESPACE), DefaultProperty(WebPartConstants.DEFAULT_XML_ROOT_PROPERTY)]
public class TestWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
public TestWebPart()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void CreateChildControls()
{
//EnsurePanelFix();
this.Controls.Add((UserControl)Page.LoadControl("~/_controltemplates/CompanyName/TestControl.ascx"));
}

/*protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Register the ScriptManager
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page); if (scriptManager == null)
{
scriptManager = new ScriptManager();
this.Controls.Add(scriptManager);
}
}*/



/*private void EnsurePanelFix()
{
if (this.Page.Form != null)
{
String fixupScript = @"
_spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");
function _initFormActionAjax()
{
if (_spEscapedFormAction == document.forms[0].action)
{
document.forms[0]._initialAction =
document.forms[0].action;
}
}
var RestoreToOriginalFormActionCore =
RestoreToOriginalFormAction;
RestoreToOriginalFormAction = function()
{
if (_spOriginalFormAction != null)
{
RestoreToOriginalFormActionCore();
document.forms[0]._initialAction =
document.forms[0].action;
}
}";
ScriptManager.RegisterStartupScript(this,
typeof(TestWebPart), "UpdatePanelFixup",
fixupScript, true);
}
}*/



}
}

-Made a user control

--- ascx file---------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestControl.ascx.cs" Inherits="TestControl_TestControl" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>








---code file----------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TestControl_TestControl : System.Web.UI.UserControl
{
protected void TimerFunc1(object sender, EventArgs e)
{
newLabel.Text = DateTime.Now.ToUniversalTime().ToString();
}
}


- Modified masterpages. Added scriptmanager control in the masterpage right under the webpartmanager tag. Set EnablePartialRendering to true and set SupportsPartialRendering to true in the asp:Scriptmanager tag. Removed return from onSubmit in form tag.

- Added web part on a page.

- Ajax worked!!

No comments: