我正在使用bootstrap(html& css),Microsoft Access和ASP.Net进行Web服务项目。
我从Bootstrap登录表格的W3Schools找到了一个代码:
<body>
<form method="POST" action="Login.aspx">
<div class="container">
<h2>Login area</h2>
<form class="form-inline" role="form">
<div class="form-group">
<label for="email">UserName:</label>
<input type="text" class="form-control" id="username1" name="username" placeholder="Enter UserName"/>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="password1" name="password" placeholder="Enter password"/>
</div>
<button type="submit" onclick="SubmitForm" class="btn btn-default">Submit</button>
</form>
</div>
这是C#代码:
protected void SubmitForm(object sender, EventArgs e)
{
if (Page.IsValid)
{
string name=string.Format("{0}",Request.Form["username"]);
string pass = string.Format("{0}", Request.Form["password"]);
int userId;
userId = LoginService.GetUserId(name, pass, 0, 1);
if (userId == 0)
{
MessageBoxShow(Page, "UserName does not exists.");
}
else
{
MessageBoxShow(Page, "You are successfully connected.");
Session["userId"] = userId.ToString();
SalService.DeleteFromSal();
}
}
}
当我运行页面并输入用户名和密码时,页面没有显示消息,我无法与用户名连接。
放一个断点,检查代码范围内发生的事情以及您收到的值。
另外,尝试使用onserverclick
代替onclick
。
<input id ="txt" runat="server" type="text">
和behine
txt.value=@Your
您的HTML未使用ASP Serveride控件格式化,但是您仍然可以使其正常工作。您必须将按钮更改为提交按钮。
<input type="submit" value="OK"/>
,然后按以下方式更改您的代码。
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string name=string.Format("{0}",Request.Form["username"]);
string pass = string.Format("{0}", Request.Form["password"]);
int userId;
userId = LoginService.GetUserId(name, pass, 0, 1);
if (userId == 0)
{
MessageBoxShow(Page, "UserName does not exists.");
}
else
{
MessageBoxShow(Page, "You are successfully connected.");
Session["userId"] = userId.ToString();
SalService.DeleteFromSal();
}
}
}
确保背后的代码是一个称为login.aspx的页面,应称为login.aspx.cs
应该有一个登录页面页面,并应有一个有效的页面指示指向背后的代码。
您还需要一个函数来进行MessageBoxShow,并应引用WebService。