The ajaxmethod function provided by coolite toolkit is the same as the pagemethod of ASP. NET Ajax. It is very easy to use. For details, refer to the following simple example:
[Ajaxmethod]
Public String pagemethod ()
{
Return "called Page POST method: pagemethod ()";
} <Ext: scriptmanager id = "scriptmanager1" runat = "server">
</Ext: scriptmanager>
<Ext: button id = "button1" runat = "server" text = "Submit">
<Listeners>
<Click handler = "requestmethod ()"
/>
</Listeners>
</Ext: button>
<SCRIPT type = "text/JavaScript">
Function requestmethod ()
{
Coolite. Ajaxmethods . Pagemethod ({
Success: function (result ){
Ext. msg. Alert ('Return prompt ', result );
}
});
}
</SCRIPT>
Use the coolie. ajaxmethods. method name provided by the coolite toolkit to directly call the POST method. Mutual Transmission Data (Simple text string, object, JSON Supports multiple formats, which is the same as ASP. NET Ajax. In addition, coolite toolkit also provides a more powerful PAGE method calling function, that is, it can call the master page and the user's Definition Controls (usercontrol. If you want to call the method on the master page, you need to provide the ajaxmethod method interface in the corresponding master page, and configure the proxy for it through ajaxmethodproxyidattribute Generate Policy, as shown in:
[Ajaxmethodproxyid (idmode = ajaxmethodproxyidmode. None)]
Public
Partial
Class mymaster: system. Web. UI. masterpage
{
[Ajaxmethod]
Public
String pagemethod ()
{
Return
"The POST method of the master page is called: pagemethod ()";
}
}
Frontend page call:
<% @ Page title = "" Language = "C #" masterpagefile = "~ /Mymaster. Master "autoeventwireup =" true"
Codebehind = "masterdemo. aspx. cs" inherits = "webapplication1.masterdemo"
%>
<Asp: Content ID = "content1" contentplaceholderid = "contentplaceholder1" runat = "server">
<Ext: scriptmanager id = "scriptmanager1" runat = "server">
</Ext: scriptmanager>
<Ext: button id = "button1" runat = "server" text = "Submit">
<Listeners>
<Click handler = "requestmethod ()"
/>
</Listeners>
</Ext: button>
<SCRIPT type = "text/JavaScript">
Function requestmethod (){
Coolite. ajaxmethods. pagemethod ({
Success: function (result ){
Ext. msg. Alert ('Return prompt ', result );
}
});
}
</SCRIPT>
</ASP: content>
If you call methods in user-defined controls, the method is not much different from the master page. The difference is that usercontrol needs to set an alias to successfully call the method. Example:
[Ajaxmethodproxyid (idmode = ajaxmethodproxyidmode. Alias, alias =
"UC")]
Public
Partial
Class timecontrol: system. Web. UI. usercontrol
{
[Ajaxmethod]
Public
String pagemethod ()
{
Return datetime. Now. tostring ();
}
}
The client uses the alias to call the following:
<Uc1: timecontrol id = "timecontrol1" runat = "server"
/>
<Ext: button id = "btnusercontrol" runat = "server" text = "Call usercontrol">
<Listeners>
<Click handler = "coolite. ajaxmethods. UC. pagemethod (
{
Success: function (result)
{
Ext. msg. Alert (result );
}
});"
/>
</Listeners>
</Ext: button>