PageMethods in ASP.NET failed to work if you have ASP.NET Routing Implemented

百般思念 提交于 2019-11-29 11:38:40

Currently, WebMethods don't work transparently with the Routing framework. There is a work around. You have to access the PageMethods directly by doing the following in your javascript:

PageMethods.set_path('/the/path/to/your/page.aspx');
PageMethods.YourMethod(params, onSuccess, onFailure);

I hope this helps.

I kept running into this myself. With routing enabled, if I added a value to the path, it would start to fail again. This solution is a bit of a hack, but it seems to be working consistently.

Create a server control hyperlink where the navigate url refers to itself, then once the control renders, grab the href and use it for set_path

This gets around the issue of set_path not referring to the correct location if you called

<asp:HyperLink ID="hlPage" runat="server" NavigateUrl="~/user.aspx" ClientIDMode="Static"></asp:HyperLink>

<script>
$(document).ready(function () {PageMethods.set_path($('#hlPage').attr('href'));})
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!