Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用页面方法_C#_Jquery_Asp.net - Fatal编程技术网

C# 调用页面方法

C# 调用页面方法,c#,jquery,asp.net,C#,Jquery,Asp.net,嗨,我有下面的pagemethod,但它似乎不起作用,我试着调试它,但它没有击中该方法。下面是我的方法的样子 function InsertStatus() { var fStatus = document.getElementById('<%=txtStatus.ClientID %>').value; PageMethods.InsertStatusUpdate(fStatus, onSucess, onError); function onSucess(resu

嗨,我有下面的pagemethod,但它似乎不起作用,我试着调试它,但它没有击中该方法。下面是我的方法的样子

function InsertStatus() {

  var fStatus = document.getElementById('<%=txtStatus.ClientID %>').value;
  PageMethods.InsertStatusUpdate(fStatus, onSucess, onError);

  function onSucess(result) {
      alert(result);
  }

  function onError(result) {
      alert('Cannot process your request at the moment, please try later.');
  }
}
当我点击我的按钮时,它直接通过onError方法。有人能看出我做错了什么吗?
我发现在方法上方需要[System.Web.Script.Services.ScriptService]的问题,因为脚本正在调用它。谢谢你的建议。

如果让我猜的话,我会把重点放在以下几点上:

 intUserID = Convert.ToInt32(HttpContext.Current.User.Identity.Name); 
解决这个问题的最好方法是设置一个断点并开始遍历代码。当您运行一行并被重定向到错误页面时,您发现了问题


我之所以选择这一行,是因为用户是一个字符串。现在,您的用户可能是数字,但也可能包括域用户==“mydomain/12345”,这不是整数,即使字符串的用户部分是。

据我所知,您不能
响应。在
页面方法中重定向

返回重定向URL的字符串,然后使用JavaScript
document.location.href
处理重定向


编辑:我刚刚看到您尝试了调试,但该方法未被命中:确保您的
ScriptManager
已将
EnablePageMethods
设置为
true

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>


看看这个页面上是否有启用了客户端方法的脚本管理器?这可能就是为什么服务器上的断点永远不会被击中的原因。嗨,我的用户是我用另一种方法验证过的数字。谢谢,我已经设置了enablepagemethods,现在,它在母版页中,这有关系吗?。
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>