- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了一个问题,我似乎无法找到以下解决方案:
我有一个包含菜单的母版页,菜单中的每个链接都是一个 LinkButton。
我需要每当用户单击某个链接以显示登录弹出窗口时,我使用了 Ajax ModalPopupExtender 并成功显示了弹出窗口。
现在我想验证用户,这意味着我需要输入用户名和密码并按登录,但由于我在弹出窗口中,它会因为回发而关闭,所以我抑制了回发,现在我必须进行检查从客户端,所以我需要从 javascript 函数调用服务器方法,我尝试使用 PageMethods,但我一直没有定义 PageMethdos,然后我读到它在母版页或用户控件中不起作用。
我的问题有什么解决方案吗?
最佳答案
PageMethods 将在 aspx 页面中使用,而不是在 MasterPage 方法中使用。唯一的解决方法是创建一个单独的 .asmx WebService 并将您的逻辑添加到一个静态函数中。为此,请在 VS 上右键单击您的解决方案,然后单击“添加新项”,选择“WebService.asmx”。在 WebService 的代码后面写一个静态的 webMethod
[WebMethod]// press alt+shift+f10 after selecting the WebMethod wording to include the library
public static bool CheckLogin (string username, string password){
//Type your method here
return result;//Result should be Boolean
}
现在在客户端脚本的 masterPage.master 上单击链接事件,向 Web 服务发布 Ajax 请求
$.ajax({
type: "POST",
url: "YourWebServiceName.asmx/CheckLogin",
data: '{"Username":"' + $('#username').val() + '","password":"' +
$('#password').val() + '"}',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(message) {
alert(message);//will alert 'true'
//DO what you want to do on client side
},
error: function() {
alert(message);//will alert 'false'
//DO what you want to do on client side
}
});
如果您需要进一步说明,请告诉我 祝你有美好的一天:)
关于c# - PageMethods 或母版页中的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19785219/
我正在设置 PageMethods 以使用 javascript 访问服务器端代码。当我使用 firebug 进行调试时,我收到错误“PageMethods 未定义”。服务器端代码也没有被触发。 我已
我有以下方法背后的代码,我想使用 JScript 调用它 VB代码 Public Shared Function SayHello() As String Return
此代码从后面的代码中的公共(public)静态字符串获取返回值,并显示警报中返回的内容。 function GetFromServer() { PageMethods.GetHello(OnGetH
我正在尝试获取此 ASP.NET 函数的值: [ScriptMethod, WebMethod] public static bool checkRefresh() { return isCh
您好,我们使用 jquery 发送 ajax 请求,但它每次都会返回页面的内容。我们正在使用 .NET Framework 版本 2 $.ajax({ type: "POST", url: "ajax
我遇到了一个问题,我似乎无法找到以下解决方案: 我有一个包含菜单的母版页,菜单中的每个链接都是一个 LinkButton。 我需要每当用户单击某个链接以显示登录弹出窗口时,我使用了 Ajax Mo
我的页面上有很多页面方法。每种方法都用于从数据库中获取数据。我按照以下方式订购了它们。但我的问题是成功方法之外但主函数内部的行在页面方法完成该过程之前正在工作 function check_valid
以下是我对服务器端方法调用 PageMethod 的实现。它当前正在生成此错误消息“未捕获的 ReferenceError:PageMethod 未定义”。我可以在 Chrome Javascript
我有一个带有 MasterPage 的页面,在母版页中,我有这个: 我在后面的代码中有这个方法: [WebMethod] public void SavePreference(string gra
我有一个非常简单的 PageMethod 调用。当我单步执行 .cs 文件中的 PageMethod 时,该值看起来符合预期。但是,在客户端,我得到一个未定义的结果。有任何想法吗?这应该非常简单。 这
我正在做一个网站,用户可以在其中回复主题、打开主题等,当用户发送消息时,我不想回发;它很丑。 我现在正在使用通用处理程序,但我遇到了一些问题。就像在 XMLHttpRequest 的 onreadys
我正在尝试“AJAX 化”我的网站以改善 UI 体验。在性能方面,我也在尝试摆脱 UpdatePanel。我在 Encosia 上看到了一篇很棒的文章显示使用 PageMethods 发布的方式。我的
我正处于使用 Jquery 开发网站的早期阶段。我想知道是否使用 Pagemethods 还是 WCF 服务类。我在一个 SO 答案中看到,它说在未来的所有需求中尽可能使用 WCF。如果有人能解释什么
我有一个对 C# WebMethod 的 javascript 调用。同一页面有另一个调用,并且正在运行。我调试了 javascript 代码,这叫做: function userUpdReq_onO
我到处搜索这个解决方案。任何见解将不胜感激。 情况:当在单个页面中有多个 PageMethod 调用时,每个方法调用都持有 Session 对象的锁,从而阻塞。只有当 @Page 指令变为 False
我正在尝试使用 PageMethods 从服务器端调用一个函数,但我收到一个错误,指出 PageMethods 未定义。 这是我在 html 中添加的内容 这是后面代码中的函
编辑:帖子底部的最新信息。 我在使用 __doPostBack 强制回发的页面上有一个更新面板。 当我在 /path/page.aspx 浏览它时一切正常。 但是,一旦我通过像 /otherpath/
我编写了一个 JavaScript 函数,当用户在 RadConfirm 对话框中单击“确定”时会触发该函数。这应该会触发服务器的 JavaScript 回调,以从数据库中删除记录。这可能不是最好的架
我读过类似问题的几个答案,但没有一个回答我的问题。我已经尝试了我能想到的一切。我的代码如下所示: function onSuccess() { alert("succe
我正在开发一个 ASP.Net 应用程序,在使用 JavaScript 调用后台代码中的函数时遇到了一些麻烦。 这是我尝试运行的 JavaScript 函数: PageMethods.EditReco
我是一名优秀的程序员,十分优秀!