我有一个div,上面有3个文本框字段,我正在使用
asp:RequiredFieldValidator和asp:CompareValidator
更改密码按钮单击div可见
protected void btnPass_Click(object sender, EventArgs e)
{
chngPwd.Visible = true;
}
并在按钮上取消将visible属性设置为false,但它不会隐藏。
protected void btnCancel_Click(object sender, EventArgs e)
{
chngPwd.Visible = false;
}
ASP代码如下
<div runat="server" id="chngPwd" visible="false" style="margin-left: 40px">
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:Label ID="lblOldP" runat="server" Text="Old Password: -"></asp:Label>
<asp:TextBox ID="txtOldP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
</div>
<br />
<br />
</div>
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtOldP" CssClass="text-danger" ErrorMessage="The Old Password field is required." />
<br />
</div>
</div>
<br />
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:Label ID="lblNewP" runat="server" Text="New Password: -"></asp:Label>
<asp:TextBox ID="txtNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
</div>
<br />
<br />
</div>
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtNewP" CssClass="text-danger" ErrorMessage="The New Password field is required." />
<br />
</div>
</div>
<br />
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:Label ID="lblRNewP" runat="server" Text="Confirm New Password: -"></asp:Label>
<asp:TextBox ID="txtRNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
</div>
<br />
<br />
</div>
<div>
<div class="col-md-4"></div>
<div class="col-md-8">
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Confirm New Password field is required." />
<br />
<asp:CompareValidator runat="server" ControlToCompare="txtNewP" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Password doesn't match." />
<br />
</div>
</div>
<br />
<div>
<div class="col-md-8"></div>
<div class="col-md-4">
<asp:Button ID="btnSbmt" runat="server" Text="Submit" OnClick="btnChngP_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
</div>
</div>
<br />
<br />
<div>
答案 0 :(得分:3)
所以你的问题是验证器按预期工作。 btnclick正在关闭,但没有调用,因为你有一个验证器。如果您输入信息然后点击取消,div将隐藏。但是你已经设置为不运行任何东西,除非那些文本框被填充。
所以我们会改变这个
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
到这个
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" CausesValidation="false"/>