Scenario:
I like to use AJAX Tab control in SharePoint as a web part.
For this I created an ASCX user control that contains the AJAX tab control and test the user control in ASP.Net's ASPX page. After successfully running the AJAX tab control in ASPX page, I use the tab control in Web part (regarding how to use ASCX in Web part, please refer earlier post).
Note: While testing the tab control in ASPX page, I kept the Script Manager element in the ASCX page. Later on while deploying the tab control in SharePoint, I moved the Script Manager element to Master page (mentioned in detail in current article at a later stage).
Steps:
1) Install ASPAJAXExtSetup.msi
C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025
2) Made following changes to site web.config :
Note: In this link it is mentioned in detail ---
http://www.asp.net/ajax/documentation/live/ConfiguringASPNETAJAX.aspx
a) <sectionGroup>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler"
type="
System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="Everywhere" />
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
<section name="authenticationService"
type="
System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
-------
-------
</configSections>
-------
-------
</configuration>
b) <controls>
<pages enableSessionState="false" enableViewState="true"
enableViewStateMac="true" validateRequest="false"
pageParserFilterType="
Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter,
Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
-----
-----
</pages>
c) <assemblies>
<compilation batch="false" debug="true">
<assemblies>
-----
-----
<add assembly="System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</assemblies>
-----
-----
</compilation>
d) <httpHandlers>
<httpHandlers>
------
------
<add verb="*" path="Reserved.ReportViewerWebControl.axd"
type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms,
Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<add verb="*" path="*_AppService.axd"
validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<add verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
e) <httpModules>
<httpModules>
------
------
<add name="ScriptModule"
type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</httpModules>
f) <SafeControls>
<SafeControls>
-----
-----
<SafeControl Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TypeName="*"
Safe="True" />
</SafeControls>
g) <system.web.extensions>
<configuration>
------
------
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to enable the authentication
service. Include requireSSL="true"
if appropriate. -->
<!--
<authenticationService enabled="true"
requireSSL = "truefalse"/>
-->
<!-- Uncomment these lines to enable the profile service.
To allow profile properties to be retrieved and modified in
ASP.NET AJAX applications, you need to add
each property name to the readAccessProperties and
writeAccessProperties attributes.
-->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2
" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true"
enableCaching="true" />
-->
</scripting>
</system.web.extensions>
</configuration>
h) <system.webServer>
<configuration>
------
------
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule"
preCondition="integratedMode"
type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*"
path="*.asmx"
preCondition="integratedMode"
type="
System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices"
verb="*" path="*_AppService.axd"
preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource"
preCondition="integratedMode"
verb="GET,HEAD"
path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
</configuration>
3) Adding a ScriptManager into a SharePoint MasterPage
Note: If you are using custom master page, then directly made required change in that. Otherwise, if you are using the default master page, then open your desired SharePoint site in SharePoint Designer. Open the default.master file located at “http:///_catalogs/masterpage/default.master” in SharePoint designer and made the required change in it.
Add the following into the markup of your page. A recommended location is right beneath the
WebPartManager registration (search for <WebPartPages:SPWebPartManager id="m" runat="Server" />).
<asp:ScriptManager runat="server" ID="
ScriptManager1 "></asp:ScriptManager>
4) In Web part solution you have to add the reference of
System.Web.Extensions.
5) Following is the code of Web part file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace BlastWP
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:SampleAJAXTab runat=server>")]
public class SampleAJAXTab : WebPart
{
private Control _control;
protected override void CreateChildControls()
{
this.EnsureUpdatePanelFixups();
_control = this.Page.LoadControl
(@"~/UserControls/BlastWP/TabbedPhases.ascx");
this.Controls.Add(_control);
}
private void EnsureUpdatePanelFixups()
{
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] =
"_spFormOnSubmitWrapper();";
}
}
ScriptManager.RegisterStartupScript(this,
typeof(SampleAJAXTab), "UpdatePanelFixup",
"_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper=true;", true);
}
}
}
Note: Here there is a hack related to AJAX Update Panel (refer method EnsureUpdatePanelFixups()).
6) After building the Web part solution, you have to follow normal steps like:
a) Strong name the Web part solution.
b) Create a *.webpart file.
c) Register dll in GAC.
d) Make entry of dll in site's config file.
e)Import *.webpart file in SharePoint.
Note: Currently the Tab headers are not coming properly in AJAX tab control.
Sample References:
- AJAX Control Toolkit
http://www.codeplex.com/AtlasControlToolkit
- Installing ASP.NET AJAX
http://www.asp.net/ajax/documentation/live/InstallingASPNETAJAX.aspx
- ASP.Net AJAX
http://asp.net/ajax/default.aspx
- Configuring ASP.NET AJAX
http://www.asp.net/ajax/documentation/live/ConfiguringASPNETAJAX.aspx
- Using the AJAX Control Toolkit in SharePoint
http://weblogs.asp.net/jan/archive/2007/02/26/using-the-ajax-control-toolkit-in-sharepoint.aspx