Use Ajax in. net3.5 in Moss

Source: Internet
Author: User
There are many articles on how to use the ajax1.0 framework in Moss. In fact, since the release of. net3.5, Ajax has been provided in. net3.5. This document describes how to use Ajax in. net3.5 in vs2005 and how to use Ajax in. net3.5 in Moss.

First, you must download a. net3.5 file.
The following describes the differences between the use and configuration of ajax1.0 and ajax1.0. the specific use of Ajax in. net3.5 is similar to that of ajax1.0, and there are many articles in the garden.

I. Use it in vs2005
Before ajax1.0, you can download a vs2005 plug-in. After installation, a specific Ajax project will be added. You can use the ajax1.0 function to create this type of project.
This plug-in mainly does two things:
1. Add some configuration items to the Web. config of the website.
In. net3.5, We can manually add Ajax configuration in Web. config: <Remove verb = "*" Path = "*. asmx"/>
<Add verb = "*" Path = "*. asmx "Validate =" false "type =" system. web. script. services. scripthandlerfactory, system. web. extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/>
<Add verb = "*" Path = "* _ appservice. axd "Validate =" false "type =" system. web. script. services. scripthandlerfactory, system. web. extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/>
<Add verb = "Get, head" Path = "scriptresource. axd "type =" system. web. handlers. scriptresourcehandler, system. web. extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "Validate =" false "/>
</Httphandlers>
<Httpmodules>
<Add name = "scriptmodule" type = "system. Web. Handlers. scriptmodule, system. Web. Extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Httpmodules>

The configuration is simpler than that of ajax1.0, and is also used. net is a more standard method, by registering some httphandle and httpmodule to capture specific Ajax requests to achieve asynchronous refresh effect.

2. Add the Ajax control to the toolbox.
You can also right-click the toolbox in vs2005 and select an item ...., then in ".. NET Framework component. web. extensions (3.5.0.0) control, you can insert it.
After adding it, you will see the corresponding controls in the toolbox (of course, only some basic controls), and then you can develop them using the ajax1.0 method.

2. Use Ajax in. net3.5 in Moss
1. modify the configuration
This step is the same as above. You can add the above configuration to the Web. config file of the corresponding Moss site.

2. Compile webpart in vs2005
This is also a normal way to write a webpart and use the Ajax control in this webpart. However, your webpart must be specially processed for Ajax. I wrote a parent class for reference on the Internet. You can directly inherit from this parent class. 1 public abstract class ajaxbasepart: system. Web. UI. webcontrols. webparts. webpart
2 {
3 private scriptmanager _ ajaxmanager;
4
5 Public ajaxbasepart ()
6 {
7}
8
9 protected override void oninit (eventargs E)
10 {
11 base. oninit (E );
12
13 // obtain the existing scriptmanager
14 _ ajaxmanager = scriptmanager. getcurrent (this. Page );
15
16 if (_ ajaxmanager = NULL)
17 {
18 // create a scriptmanager
19 _ ajaxmanager = new scriptmanager ();
20 _ ajaxmanager. ID = This. ID + "$ ajaxmanager ";
21 _ ajaxmanager. enablepartialrendering = true;
22
23 if (this. Page. form! = NULL)
24 {
25 // solve the problem that the Ajax button can only be executed once
26 string formonsubmitatt = This. Page. Form. attributes ["onsubmit"];
27 if (! String. isnullorempty (formonsubmitatt) & formonsubmitatt = "Return _ spformonsubmitwrapper ();")
28 {
29 This. Page. Form. attributes ["onsubmit"] = "_ spformonsubmitwrapper ();";
30}
31
32 This. Page. Form. Controls. addat (0, _ ajaxmanager );
33}
34}
35}
36}

The main code is as follows:
1. Get the scriptmanager object in lines 14. If there is no scriptmanager object, create it and insert it as the first control of form in line 32. Because only one scriptmanager object can appear on a page
2. between 26 and 30, the updatepanel button can only be executed once. There are some compatibility issues when using Ajax controls directly in Moss, which requires special processing. If you do not add this code, you can only click the button that appears in updatepanel once. The button does not respond when you click it again next time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.