【IT168技术文档】
以前遇到这个问题,一懒就绕过去了...没想到今天又碰见,再绕过去就该bs自己了。
以下代码是内容页的部分代码:
cs文件:
aspx文件:namespace CnBlogs.Garfield { public partial class TestPage: PageBase { protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(typeof(TestPage)); // } // } }
注册page类或者起个别名,然后在客户端使用这个名字调用ajax方法,平时在页面里我们都是这么用的,可是如果这个页面是个内容页的话,你会发现出错了,客户端提示“TestPage is undefined”。<script type="text/javascript"> <!-- function test() { TestPage.DoSomething( function ( result ) { // } ); } --> </script>
为什么呢?
打开页面的源码看一下,ajaxpro注册了好几个脚本,类似:
恩~~最后一个应该是我们比较感兴趣的...<script type="text/javascript" src="/ajaxpro/prototype.ashx"></script> <script type="text/javascript" src="/ajaxpro/core.ashx"></script> <script type="text/javascript" src="/ajaxpro/converter.ashx"></script> <script type="text/javascript" src="/ajaxpro/CnBlogs.Garfield.TestPage,CnBlogs.Garfield.ashx"></script>
访问一下:http://www.test.com/ajaxpro/CnBlogs.Garfield.TestPage,CnBlogs.Garfield.ashx
哈,看到了吧,最后一句是
这个全局变量的名字不再是TestPage,而变成了类的全名:命名空间+类名。CnBlogs.Garfield.TestPage = new CnBlogs.Garfield.TestPage_class();
剩下就没什么说的了,用CnBlogs.Garfield.TestPage.DoSomething()试试吧...