Wednesday, February 4, 2009

Existing asp.net page to AJAX enabled page in Sharepoint

Adding Microsoft ASP.NET AJAX Technology to SharePoint Pages
To extend your SharePoint site with Microsoft ASP.NET AJAX 1.0, need to perform a few steps.
• First, need to download and install ASP.NET AJAX on servers
• Second, need to extend web.config with some settings to enable ASP.NET AJAX technology.
• Third, need to add the ASP.NET AJAX Script Manager into master page to enable scenarios such as Extenders or UpdatePanels.

A. Installing Microsoft ASP.NET AJAX 1.0
After installing add Reference ,System.Web.Extensions.
B. Extending SharePoint web.config files with Microsoft ASP.NET AJAX 1.0
Extending SharePoint web.config files with ASP.NET AJAX requires the some Ajax registration entries in-line with WSS registration entries. To do this we need to edit SharePoint web.config file.
1. Add a element to the tag:












2. Add a section as a child of the / tag:





3. Add the following tag to the tag, within :


----This has come by installing AJAX
4. Add some new registrations to the end of the section:





5. Add a new registration to the HttpModules section, beneath any existing registrations:



6. Add a SafeControl entry for the System.Web.UI namespace from Microsoft Ajax Extensions, within the /section:



7. Finally, add the following configuration tags at the bottom of web.config, near the bottom before the end tag:


















type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>




C. Adding a ScriptManager into a SharePoint MasterPage
To statically embed a script manager into a page, it is recommended that, add the ScriptManager into the master page of a site.
To do this, open up the master page for your site. Typically, this will be located at /_catalogs/masterpage. You can edit this file by opening it in an editor such as Microsoft SharePoint Designer, or directly in Notepad by opening your master page library via DAV (typically \\server\\_catalogs\masterpage.)
Add the following into the markup of your page. A recommended location is right beneath the WebPartManager registration (search for ):

D. Using UpdatePanels within SharePoint
UpdatePanels are a very useful addition to ASP.NET AJAX, and represent the simplest way to convert existing, standard ASP.NET controls and parts to take advantage of Ajax techniques. However, there are some changes within Windows SharePoint Services which may get in the way of working with ASP.NET AJAX.
Windows SharePoint Services JavaScript has onSubmit wrapper which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.
To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:

This script may be directly embedded in the page, or could be emitted by a control that uses the UpdatePanel.
E. Modify Windows SharePoint Services 3.0 scripts to change doPostBack() behavior
To modify scripts to ensure proper doPostBack() behavior
For ASP.NET controls that use the JavaScript _doPostBack() function to commit changes, a regular full-page postback event may occur even when the Web Part is inside an UpdatePanel control. Windows SharePoint Services 3.0 and ASP.NET AJAX cache certain form actions, which can cause a conflict between SharePoint and ASP.NET AJAX. To change this behavior, you must add code to scripts that are running in Windows SharePoint Services 3.0.
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;
}
}";
}
}

No comments: