I have a website that I log into. In my pages that are viewable while logged in, there is a logout button that logs the user out and takes the user back to the login page. The problem is on certain pages, I have textboxes that have requiredFieldValidators. Now when I hit the logout button, the requiredFieldValidators for the textboxes pop up and won't let me log out.
What do I need to change?
protected void btLogout_Click(object sender, EventArgs e)
{
Session.Abandon();开发者_开发知识库
Session.Contents.RemoveAll();
System.Web.Security.FormsAuthentication.SignOut();
Response.Redirect("~/Default.aspx");
}
Use the following on your log-out button declaration:
CausesValidation="false"
You need to set the ValidationGroup
property for the validators and controls you want to validate and make sure that the Log Out button is not part of the group.
精彩评论