(1) Moss Ajax Configuration
1. Microsoft SharePoint Team blog solution, integrating ASP. NET Ajax with SharePoint
2. Configure Moss Ajax webparts development environment using stsadm. ajaxifymoss
3. Download ajaxify moss from the stsadm. ajaxify Solution
Basically, it is to modify the Web. config file of the application. There are roughly seven
(2) A simple Ajax Hello webpart
1. First, develop a base class webpart to check the registration of scriptmanager and so on.
Code
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web. UI. webcontrols. webparts;
Using Microsoft. Sharepoint. webpartpages;
Using system. Web. UI;
Public class baseajaxwebpart: system. Web. UI. webcontrols. webparts. webpart
{
Private scriptmanager _ ajaxmanager;
// Customize a scriptmanager to store the obtained scriptmanager
[Webpartstorage (storage. None)]
Public scriptmanager ajaxmanager
{
Get {return _ ajaxmanager ;}
Set {_ ajaxmanager = value ;}
}
// Page initialization event
Protected override void oninit (eventargs E)
{
Base. oninit (E );
// Obtain the scriptmanager on the page
_ Ajaxmanager = scriptmanager. getcurrent (this. Page );
// If there is no scriptmanager on the page, append
If (_ ajaxmanager = NULL)
{
_ Ajaxmanager = new scriptmanager ();
_ Ajaxmanager. enablepartialrendering = true;
Page. clientscript. registerstartupscript (typeof (baseajaxwebpart), this. ID, "_ sporiginalformaction = Document. Forms [0]. Action;", true );
If (this. Page. form! = NULL)
{
String formonsubmitatt = This. Page. Form. attributes ["onsubmit"];
If (! String. isnullorempty (formonsubmitatt)
& Formonsubmitatt = "Return _ spformonsubmitwrapper ();")
{
This. Page. Form. attributes ["onsubmit"] = "_ spformonsubmitwrapper ();";
}
This. Page. Form. Controls. addat (0, _ ajaxmanager );
}
}
}
/* In Moss, in order to correctly parse certain special URLs, such as URLs containing Chinese characters and other two-bit characters,
* Windows SharePoint Services JavaScript uses form onsubmit wrapper to reload the default form action,
* The following method restores the default form action. If your url does not contain double-byte characters such as Chinese characters,
* Congratulations, you can use ASP. NET Ajax updatepanels
* (For details, refer to the "Moss Development Team blog" mentioned above 」)*/
Protected 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 (baseajaxwebpart ),
"Updatepanelfixup ",
"_ Sporiginalformaction = Document. Forms [0]. Action; _ spsuppressformonsubmitwrapper = true ;",
True );
}
Protected void registerasyncpostbackcontrol (Control)
{
If (control! = NULL)
{
_ Ajaxmanager. registerasyncpostbackcontrol (control );
}
}
Protected override void createchildcontrols ()
{
Base. createchildcontrols ();
This. ensureupdatepanelfixups ();
}
}
2. hellowebpart code
Code
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using Microsoft. Sharepoint. webpartpages;
Namespace webpart. Test
{
Public class ajaxsayhellowebpart: baseajaxwebpart
{
Private Label label;
Private textbox;
Private updatepanel up;
Private button;
// Create various controls and fill in updatepanel
Protected override void createchildcontrols ()
{
Base. createchildcontrols ();
Up = new updatepanel ();
Up. ID = "updatepanel1 ";
Up. childrenastriggers = true;
Up. rendermode = updatepanelrendermode. inline;
Up. updatemode = updatepanelupdatemode. Always;
This. textbox = new Textbox ();
This. textbox. ID = "textbox ";
Up. contenttemplatecontainer. Controls. Add (this. textbox );
This. Label = new label ();
This. Label. Text = "enter your name .";
Up. contenttemplatecontainer. Controls. Add (this. Label );
This. Button = new button ();
Button. causesvalidation = false;
Button. ID = "button1 ";
Button. Text = "Say hello ";
Button. Click + = new eventhandler (handlebuttonclick );
Up. contenttemplatecontainer. Controls. Add (this. Button );
Base. registerasyncpostbackcontrol (this. Button );
This. Controls. Add (up );
}
Private void handlebuttonclick (Object sender, eventargs)
{
This. Label. Text = "hello" + this. textbox. text;
}
}
}
3. After packaging and publishing,
Enter "XXXX" in the input box and click "Say hello". The label will display "Hello XXXX ".