我有一个我在我的应用程序中使用的引导模式,当我单击提交按钮时模式已关闭,因此无法显示错误消息。
有没有办法阻止在提交时重新加载页面?
提交按钮:
<asp:Button runat="server" OnClick="PasswordChange" id="passwordChange" Text="Save" CssClass="btn btn-default"></asp:Button>
错误消息:
<asp:Label runat="server" ID="error1"></asp:Label>
C#:
protected void PasswordChange(object sender, EventArgs e)
{
string currentPassword = cPassword.Text.ToString();
string newPassword = nPassword.Text.ToString();
string rePassword = rPassword.Text.ToString();
db_connection();
if (newPassword == rePassword)
{
Debug.WriteLine("Success" + newPassword + rePassword);
}
else
{
error1.Text = "Your passwords did not match, please try again";
}
}
答案 0 :(得分:0)
使用ajax可以防止刷新,例如
$("#passwordChange").click(function (event) {
var n = $('#nPassword').val();
var r = $('#rPassword').val();
if (n != r || n == "") {
$('.passwordError').show();
event.preventDefault();
}
});