ASP.NET AJAX(Atlas)现存的一些常见问题以及解决方案
2006-11-09 21:47
821 查看
根据这一周的用户反馈来讲,ASP.NET AJAX(Atlas)从CTP到Beta 1,不能说是一个“进步”,当然也不能说是“退步”。作为一个变化如此巨大的新版本,ASP.NET AJAX似乎有些不够稳定,本文将列举出一些开发者社区中常见的问题以及相应的解决方案,并将不断更新,希望对各位朋友有所帮助。
以下两条来自微软公司的总监Shawn Burke的Blog(http://blogs.msdn.com/sburke/)。
1.从客户端调用Web Method时发生[Method Error 12031]或[Method Error 500]异常
若要从客户端调用某个服务器端Web Service中的Web Method,则该Web Service必须拥有Microsoft.Web.Script.Services.ScriptServiceAttribute属性:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[Microsoft.Web.Script.Services.ScriptService()]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class MyService : System.Web.Services.WebService ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
若要从客户端调用某个定义与页面中的Page Method,则该Page Method必须用Microsoft.Web.Script.Services.ScriptMethodAttribute属性修饰(当然,System.Web.Services.WebMethod也是必不可少的),且必须为静态(static)方法。目前版本的一个Bug还导致我们必须在ASPX文件中定义这个Web Method,在CS文件中定义是没有作用的(真是无奈):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<script runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[System.Web.Services.WebMethod]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[Microsoft.Web.Script.Services.ScriptMethod]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public static string GetHtml(string contextKey) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
2.在模板控件(例如Login)或者数据绑定控件(例如GridView)中,Extender Control(包括AJAX Control Toolkit)无法正常工作
原因在于,Beta 1中所有的客户端脚本统一由ScriptManager管理,而ScriptManager是在PreRender时期遍历页面中的控件并输出必要的客户端脚本,但模板中的内容通常也是在PreRender时才生成的,这样二者错失了沟通的机会,自然模版中的Extender Control所必须的客户端脚本将不会被发送至浏览器,也就最终导致了Extender Control无法在模板控件中使用。
解决方法就是在PreRender之前,例如Load事件中强制让页面生成模版控件或数据绑定控件的内容,这样在PreRender的时候ScriptManager就可以正确找到他们了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind(); // 数据绑定控件用这个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
object o = Login1.Controls; // 模版控件用这个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
转自http://www.cnblogs.com/dflying/archive/2006/10/27/ASPNET_AJAX_Beta_1_FAQ.html
以下两条来自微软公司的总监Shawn Burke的Blog(http://blogs.msdn.com/sburke/)。
1.从客户端调用Web Method时发生[Method Error 12031]或[Method Error 500]异常
若要从客户端调用某个服务器端Web Service中的Web Method,则该Web Service必须拥有Microsoft.Web.Script.Services.ScriptServiceAttribute属性:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[Microsoft.Web.Script.Services.ScriptService()]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class MyService : System.Web.Services.WebService ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
若要从客户端调用某个定义与页面中的Page Method,则该Page Method必须用Microsoft.Web.Script.Services.ScriptMethodAttribute属性修饰(当然,System.Web.Services.WebMethod也是必不可少的),且必须为静态(static)方法。目前版本的一个Bug还导致我们必须在ASPX文件中定义这个Web Method,在CS文件中定义是没有作用的(真是无奈):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<script runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[System.Web.Services.WebMethod]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
[Microsoft.Web.Script.Services.ScriptMethod]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public static string GetHtml(string contextKey) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
2.在模板控件(例如Login)或者数据绑定控件(例如GridView)中,Extender Control(包括AJAX Control Toolkit)无法正常工作
原因在于,Beta 1中所有的客户端脚本统一由ScriptManager管理,而ScriptManager是在PreRender时期遍历页面中的控件并输出必要的客户端脚本,但模板中的内容通常也是在PreRender时才生成的,这样二者错失了沟通的机会,自然模版中的Extender Control所必须的客户端脚本将不会被发送至浏览器,也就最终导致了Extender Control无法在模板控件中使用。
解决方法就是在PreRender之前,例如Load事件中强制让页面生成模版控件或数据绑定控件的内容,这样在PreRender的时候ScriptManager就可以正确找到他们了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind(); // 数据绑定控件用这个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
object o = Login1.Controls; // 模版控件用这个
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
转自http://www.cnblogs.com/dflying/archive/2006/10/27/ASPNET_AJAX_Beta_1_FAQ.html
相关文章推荐
- ASP.NET AJAX(Atlas)现存的一些常见问题以及解决方案[持续更新]
- 现存问题以及解决方案:在ASP.NET AJAX客户端得到服务器端的DataTable
- ASP.NET AJAX 1.0资源连接以及对一些常见问题的答复
- ASP.NET AJAX 1.0资源连接以及对一些常见问题的答复
- 现存问题以及解决方案:在ASP.NET AJAX客户端得到服务器端的DataTable
- 现存问题以及解决方案:在ASP.NET AJAX中从客户端向服务器端传送DataTable
- 现存问题以及解决方案:在ASP.NET AJAX中从客户端向服务器端传送DataTable
- 转载: asp.net ajax UpdatePanel使用技巧以及常见问题
- ASP.NET高级程序员进阶之路——.net项目开发中一些常见的代码规范问题及解决方案
- asp.net ajax UpdatePanel使用技巧以及常见问题
- iis配置asp.net常见问题解决方案
- 配置asp.net IIS服务器遇到的问题以及详细图例解决方案
- asp.net ajax updatepanel 乱码问题 最完美解决方案
- ASP.NET AJAX正式版带来的Validator问题及解决方案
- 关于AJAX跨域调用ASP.NET MVC或者WebAPI服务的问题及解决方案
- asp.net session过期原因以及一些解决方案
- ASP.NET AJAX正式版带来的Validator问题及解决方案
- ASP.NET中对Exception的统一集中处理常见的有两种方式的一些问题总结
- asp.NET C#开发中的一些常见的问题集锦
- ASP.NET中关于网站统计的一些常见问题