weixin_33739541 2011-04-28 12:02 采纳率: 0%
浏览 45

未定义PageMethods

I am setting up PageMethods to access server side code using javascript. I am receiving the error "PageMethods is not defined" when i debug using firebug. the server side code is not being fired as well.

I have setup my script manager "EnablePageMethods" to true. My method is public & static and it has the WebMethod attribute set up as well. Still i m receiving the above error. Can it be because of the script manager being in a top level master page which has two child master pages and then my page is called:

i.e.

Main Master Page (with script manager) -> Primary master page -> Secondary master page -> My page -> My User control (having the WebMethod)

Is it possible tht the hierarchy is causing this issue?

This is the webmethod

 [System.Web.Services.WebMethod]
public static void AddNote(string t)
{
    int propid = 1; 
    if (propid > 0)
    {
     //Call my method
    }
}

this is my javascript code:

  function editNodes(t) {
    alert('test1');
    alert(t);
    PageMethods.AddNote(t,OnSuccess,OnFailure);
    alert('method called');
}
function OnSuccess() { 
    alert('Success'); 
    if (!navigator.appName == 'Microsoft Internet Explorer') {
        window.location.href = window.location.href;
    }

}
function OnFailure(error) {
    alert('Error:' + error);
}    

this is where I am calling it:

   <a href="#" class="btngeneral" onclick="javascript:editNodes(2);">Save</a>
  • 写回答

3条回答 默认 最新

  • weixin_33712987 2011-04-28 12:49
    关注

    As far as I understand, PageMethods on usercontrol is not supported and threads below seem to confirm that

    http://forums.asp.net/p/977525/1242935.aspx

    ASP.NET AJAX Page Methods from UserControl

    But I think there could be a workaround (not sure if that's efficient in your scenario). You can write a OneLine PageMethod in page's code behind which would intern call the Controls Page method. Now you can invoke your page's method from aspx and all set to go.

    Or you may use ths alternative Alternate way to use page method inside user control asp.net

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R