Using ajax in Moss is quite popular now. I also want to say that the Ajax supported by Moss is not very good now. I heard that Ajax will be fully supported after Moss SP1 is released, think about moss at that time .....
Next we will introduce the simple use of Ajax in Moss. The following column is a demo I made in my website,
Hope to help you learn Moss Ajax...
I have another idea. Sometimes, it doesn't matter if you don't understand the code. First, run the code. Use it to understand pull ....
This is the moss configuration file. To use Ajax, you need the configuration file.
C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 80
1. Add the <sectiongroup> element to the <configsections> flag: <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>
2. Add the content of the <controls> section and put it in the <system. Web>/<pages> flag. <Pages>
<Controls>
<Add tagprefix = "asp" namespace = "system. Web. UI" assembly = "system. Web. Extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Controls>
</Pages>
3. Add the following content to the <assemblies> tag in the <compilation> tag: <assemblies>
<Add Assembly = "system. Web. Extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Assemblies>
4. Add the following content in the <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>
5. Add the following registration content in the httpmodules section and put it under all existing registration content <Add name = "scriptmodule" type = "system. Web. Handlers. scriptmodule, system. Web. Extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Httpmodules>
6. In the <SharePoint>/<safecontrols> section, add a safecontrol for the system. Web. UI namespace of Microsoft Ajax extensions. <Safecontrols>
<Safecontrol Assembly = "system. web. extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "namespace =" system. web. ui "typename =" * "Safe =" true "/>
</Safecontrols>
7. Add the following configuration tag to the end of the web. config file, Before the end tag <configuration>.
<System. Web. Extensions>
<Scripting>
<WebServices>
<! -- Uncomment this line to enable the authentication service. Include requiressl = "true" if appropriate. -->
<! --
<Authenticationservice enabled = "true" requiressl = "True | false"/>
-->
<! -- 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>
<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>
After the configuration file is configured, we can now develop and use Ajax ..
Using system;
Using system. runtime. interopservices;
Using system. Web. UI;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. serialization;
Using system. Web;
Using system. Web. UI. webcontrols;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. webcontrols;
Using Microsoft. Sharepoint. webpartpages;
Namespace ajaxshow
{
[GUID ("ca7e29da-ecd8-4151-baea-e75f08d0b9bd")]
Public class ajaxshow: system. Web. UI. webcontrols. webparts. webpart
{
Public ajaxshow ()
{
This. exportmode = webpartexportmode. All;
}
Updatepanel up;
Protected label Lb;
Protected timer tt;
// Scriptmanager will go to all client scripts during the prerender Period
// The control in createchildcontrol () is also created in prerpender.
// If the createchildcontrol is created, a response is generated.
Protected override void oninit (eventargs E)
{
Base. oninit (E );
Scriptmanager Sm = scriptmanager. getcurrent (this. Page );
If (Sm = NULL)
{
Sm = new scriptmanager ();
SM. ID = "SM ";
If (this. Page. ispostback)
{
Page. clientscript. registerstartupscript (typeof (ajaxshow ),
This. ID, "_ sporiginalformaction = Document. Forms [0]. Action; _ spsuppressformonsubmitwrapper = true;", 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, Sm );
}
}
}
Protected override void createchildcontrols ()
{
Base. createchildcontrols ();
Try
{
Lb = new label ();
LB. ID = "LB ";
LB. Text = "AA Ajax ";
Tt = new timer ();
TT. ID = "TT ";
TT. Enabled = true;
TT. interval = 3000;
TT. Tick + = new eventhandler <eventargs> (tt_tick );
Up = new updatepanel ();
Up. ID = "up ";
Up. contenttemplatecontainer. Controls. Add (LB );
Up. contenttemplatecontainer. Controls. Add (TT );
// Set updatepanelupda
Up. updatemode = updatepanelupdatemode. Conditional;
Asyncpostbacktrigger apbk = new asyncpostbacktrigger ();
Apbk. controlid = "TT ";
Apbk. eventname = "tick ";
Up. triggers. Add (apbk );
This. Controls. Add (up );
}
Catch (exception ex)
{
Literal errmsg = new literal ();
Errmsg. Text = ex. message;
This. Controls. Add (errmsg );
}
}
Void tt_tick (Object sender, eventargs E)
{
// Throw new exception ("the method or operation is not implemented .");
LB. Text = getquery ();
}
Protected string getquery ()
{
// Spsite site = spcontrol. getcontextsite (system. Web. httpcontext. Current );
// Spweb web = site. rootweb;
// Splist list = web. Lists ["customlist"];
Spsite site = new spsite (@ "http: // LH-VPC/personal/test ");
Spweb web = site. openweb ();
Splist list = web. Lists ["customlist"];
Splistitemcollection lists = List. items;
String strresult = "";
Int I = List. itemcount;
Int resultrank = 1;
If (I <1)
{
Strresult = "no info... haha ";
}
Else
{
Random r = new random ();
Resultrank = R. Next (1, I );
Strresult = lists [resultrank]. Name;
}
Return strresult;
}
Protected override void render (htmltextwriter writer)
{
Up. rendercontrol (writer );
}
}
}
What do you not understand... You can propose...