pagemethods仅适用于空文本框参数 [英] pagemethods work only with empty textbox parameter
问题描述
服务器端方法。这是登录表单。当我输入任何用户名和密码时,服务器端方法根本不是被调用的。如果我将文本框留空,一切正常。请帮助
< 表格 class = login-form runat = server >
< asp:ToolkitScriptManager ID = ToolkitScriptManager1 EnablePageMethods = true runat = server > < / asp:ToolkitScriptManager >
< div class = form-group >
< label class = sr-only for = form-username > 用户名< / label >
< input id = 用户名 type = text 占位符 = 用户名... class = form-username form-control / >
< / div >
< < span class =code-leadattribute> div class = form-group >
< label class = sr-only = form-password > 密码< / label >
< 输入 类型 = 密码 id = 密码 占位符 = 密码... class = form-password form-control / >
< / div >
< 按钮 class = btn onclick = CheckLogin() > 登录!< / button >
< label id = 消息 > < / label >
< / form >
以下是javascript代码。它返回用于进一步检查的数据。如果数据为真,我们存储会话并重定向到索引页。
< script >
function CheckLogin(){
var username = $(' #用户名'跨度>)VAL();
var 密码= $(' #Date 跨度>)VAL();
alert(密码);
PageMethods.LoadDetails(用户名,密码,功能(数据){
如果 (data == TRUE){
Session( Userid)= username;
window 。 location .href = index.aspx;
}
其他 {
$(' #message')。html(data);
}
});
}
< / script >
以下是vb代码。它调用一个名为Marks的类,它包含一个名为Load_Details的函数。此函数检查用户是否存在,如果存在,则返回true。
Imports System.Web .Services
< System.Web.Services.WebMethod()> _
公开 共享 功能 LoadDetails( ByVal 用户名作为 字符串,< span class =code-keyword> ByVal 密码作为 字符串)作为 字符串
Dim Mkz 作为标记= 新标记()
Dim holmes 作为 字符串
holmes = Mkz.load_Details(用户名,密码)
< span class =code-keyword>返回 holmes
结束 功能
(' #Username' 跨度>)VAL();
var password =
(' #密码跨度>)VAL();
alert(密码);
PageMethods.LoadDetails(用户名,密码,功能(数据){
如果 (data == TRUE){
Session( Userid)= username;
window 。 location .href = index.aspx;
}
else {
(' #message')。html(data);
}
});
}
< / script >
以下是vb代码。它调用一个名为Marks的类,它包含一个名为Load_Details的函数。此函数检查用户是否存在,如果存在,则返回true。
Imports System.Web .Services
< System.Web.Services.WebMethod()> _
公开 共享 功能 LoadDetails( ByVal 用户名作为 字符串,< span class =code-keyword> ByVal 密码作为 字符串)作为 字符串
Dim Mkz 作为标记= 新标记()
Dim holmes 作为 字符串
holmes = Mkz.load_Details(用户名,密码)
< span class =code-keyword>返回 holmes
结束 功能
server side method is called only if textbox is empty. This is login form. When I type any username and password, the server side method is not a called at all. If I leave the textboxes empty, everything works . Please help
<form class="login-form" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" EnablePageMethods="true" runat="server"></asp:ToolkitScriptManager>
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input id="Username" type="text" placeholder="Username..." class="form-username form-control" />
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" id="Password" placeholder="Password..." class="form-password form-control" />
</div>
<button class="btn" onclick="CheckLogin()" >Sign in!</button>
<label id="message"></label>
</form>
Below is the javascript code. It returns data that is used for further checks. If the data is true, we store a session and redirect to index page.
<script>
function CheckLogin() {
var username = $('#Username').val();
var password = $('#Password').val();
alert(password);
PageMethods.LoadDetails(username, password, function (data) {
if (data == "TRUE") {
Session("Userid") = username;
window.location.href = "index.aspx";
}
else {
$('#message').html(data);
}
});
}
</script>
below is the vb code. It calls a class called Marks which contains a function called Load_Details. This function checks to see if user exist and returns true if he does exist.
Imports System.Web.Services
<System.Web.Services.WebMethod()> _
Public Shared Function LoadDetails(ByVal Username As String, ByVal Password As String) As String
Dim Mkz As Marks = New Marks()
Dim holmes As String
holmes = Mkz.load_Details(Username, Password)
Return holmes
End Function
('#Username').val(); var password =
('#Password').val(); alert(password); PageMethods.LoadDetails(username, password, function (data) { if (data == "TRUE") { Session("Userid") = username; window.location.href = "index.aspx"; } else {
('#message').html(data); } }); } </script>
below is the vb code. It calls a class called Marks which contains a function called Load_Details. This function checks to see if user exist and returns true if he does exist.
Imports System.Web.Services <System.Web.Services.WebMethod()> _ Public Shared Function LoadDetails(ByVal Username As String, ByVal Password As String) As String Dim Mkz As Marks = New Marks() Dim holmes As String holmes = Mkz.load_Details(Username, Password) Return holmes End Function
这篇关于pagemethods仅适用于空文本框参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!