处理此类问题需要使用AjaxMethodProxyID,使用的方法是在类的前面加上,如下
[AjaxMethodProxyID(IDMode = AjaxMethodProxyIDMode.None)]
partial class ModuleRightManager : PortalModuleBase
partial class ModuleRightManager : PortalModuleBase
在有MasterPage页面或者在类似DotNetNuke的CMS系统下使用Coolite的AJAXMethod,建议你在页面的前部加上:
[AjaxMethodProxyID(IDMode = AjaxMethodProxyIDMode.ClientID)]
public partial class PopupCustomerDetail : PortalModuleBase
public partial class PopupCustomerDetail : PortalModuleBase
例子:
母版页.cs:
代码
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext.Web;
[AjaxMethodProxyID(IDMode = AjaxMethodProxyIDMode.None)]
public partial class Base : System.Web.UI.MasterPage
{
protected void Page_Load( object sender, EventArgs e)
{
}
[AjaxMethod]
public string PageMethod()
{
return " 调用了模板页的方法PageMethod(); " ;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext.Web;
[AjaxMethodProxyID(IDMode = AjaxMethodProxyIDMode.None)]
public partial class Base : System.Web.UI.MasterPage
{
protected void Page_Load( object sender, EventArgs e)
{
}
[AjaxMethod]
public string PageMethod()
{
return " 调用了模板页的方法PageMethod(); " ;
}
}
内容页:
代码
<%
@ Page Title
=
""
Language
=
"
C#
"
MasterPageFile
=
"
~/Base.master
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
test.aspx.cs
"
Inherits
=
"
test
"
%>
<% @ Register assembly = " Coolite.Ext.Web " namespace = " Coolite.Ext.Web " tagprefix = " ext " %>
< asp:Content ID = " Content1 " ContentPlaceHolderID = " head " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content2 " ContentPlaceHolderID = " ContentPlaceHolder1 " Runat = " Server " >
< ext:ScriptManager ID = " ScriptManager1 " runat = " server " />
< ext:Button ID = " Button1 " runat = " server " Text = " 点我 " >
< Listeners >
< Click Handler = "
Coolite.AjaxMethods.PageMethod({
success: function(result) {
Ext.Msg.alert( ' 提示信息 ' , result);
}
}); " />
</ Listeners >
</ ext:Button >
</ asp:Content >
<% @ Register assembly = " Coolite.Ext.Web " namespace = " Coolite.Ext.Web " tagprefix = " ext " %>
< asp:Content ID = " Content1 " ContentPlaceHolderID = " head " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content2 " ContentPlaceHolderID = " ContentPlaceHolder1 " Runat = " Server " >
< ext:ScriptManager ID = " ScriptManager1 " runat = " server " />
< ext:Button ID = " Button1 " runat = " server " Text = " 点我 " >
< Listeners >
< Click Handler = "
Coolite.AjaxMethods.PageMethod({
success: function(result) {
Ext.Msg.alert( ' 提示信息 ' , result);
}
}); " />
</ Listeners >
</ ext:Button >
</ asp:Content >
以下是几种AjaxMethodProxyID 的区别:
1. None - 命名前缀是空的,调用方法时直接使用 Coolite.AjaxMethods.ajaxMethod(...)
2. ClientID - 命名前缀需要加上当前类控件的client id(客户端前缀) ,如Coolite.AjaxMethods.ctl00_UC1.ajaxMethod ,当然通常情况下我们Coolite.AjaxMethods.<%=this.ClientID>.ajaxMethod(...)
3. ID - 使用当前控件ID作为前缀, Coolite.AjaxMethods.UC1.ajaxMethod(...)
4. Alias - 使用别名做前缀,你可以声明自己的一个别名, Coolite.AjaxMethods.myAlias.ajaxMethod(...)
5. AliasPlusID - 别名和ID同时使用,如 Coolite.AjaxMethods.myAliasUC1.ajaxMethod(...)