【发布时间】:2014-02-03 01:06:57
【问题描述】:
我正在开发一个具有管理面板和购物面板的电子商务项目。
我已经完成了编程,现在手动测试每个 aspx 和 cs 文件。
问题是,我有一个与会话和数据库相关的更改密码功能。问题是我的 aspx 文件中有一个验证器,但它们不起作用。这是我的代码;
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Panel ID="Panel1" runat="server" DefaultButton="btnChange">
<div class="userForm">
<div class="formTitle">
Change Your Password
</div>
<div class="formContent">
<asp:TextBox ID="txtPassword" placeholder="Type your new password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtPassword"
ErrorMessage="RequiredFieldValidator" ForeColor="Red" Display="Dynamic" ValidationGroup="signup">Enter a password</asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="txtAgainPassword" placeholder="Repeat your new password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" BorderColor="Red"
ControlToValidate="txtAgainPassword" Display="Dynamic" ErrorMessage="Enter password again."
ForeColor="Red" ValidationGroup="signup"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPassword"
ControlToValidate="txtAgainPassword" Display="Dynamic" ErrorMessage="Password don't match."
ForeColor="Red" ValidationGroup="signup"></asp:CompareValidator>
<br />
<asp:Button ID="btnChange" runat="server" Text="Submit" OnClick="btnChange_Click" />
<br />
<asp:Label ID="lblError" Visible="False" ForeColor="Green" runat="server"></asp:Label></div>
</div>
</asp:Panel>
</asp:Content>
.cs 部分在下面
protected void btnChange_Click(object sender, EventArgs e)
{
using (ZirveMarketDBEntities context = new ZirveMarketDBEntities())
{
// Atanan sessiona gore user bilgisini al - guvenlik icin onemli
int id = (int)Session["CustomerID"];
Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();
cust.Password = txtPassword.Text;
context.SaveChanges();
}
lblError.Visible = true;
lblError.Text = "Password successfully updated";
}
问题是,我有一个 2 框输入新密码并输入新密码。即使它们为空,即使它们不匹配密码仍然会随着第一部分的值而变化。如果它们不匹配或为空,我不想运行服务器端代码。我究竟做错了什么?帮助非常感谢。
【问题讨论】:
标签: c# asp.net sql-server asp.net-mvc-3