技术开发 频道

有关AjaxPro在内容页(相对于母板页)注册后,客户端无法调用ajax方法


【IT168技术文档】

  以前遇到这个问题,一懒就绕过去了...没想到今天又碰见,再绕过去就该bs自己了。

  以下代码是内容页的部分代码:

  cs文件:
namespace CnBlogs.Garfield { public partial class TestPage: PageBase { protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(typeof(TestPage)); // } // } }
  aspx文件:
<script type="text/javascript"> <!-- function test() { TestPage.DoSomething( function ( result ) { // } ); } --> </script>
  注册page类或者起个别名,然后在客户端使用这个名字调用ajax方法,平时在页面里我们都是这么用的,可是如果这个页面是个内容页的话,你会发现出错了,客户端提示“TestPage is undefined”。
  为什么呢?
  打开页面的源码看一下,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
  哈,看到了吧,最后一句是
CnBlogs.Garfield.TestPage = new CnBlogs.Garfield.TestPage_class();
  这个全局变量的名字不再是TestPage,而变成了类的全名:命名空间+类名。
  剩下就没什么说的了,用CnBlogs.Garfield.TestPage.DoSomething()试试吧...
0
相关文章