开发者

Logout issues with validators on the page. ASP.NET C#

开发者 https://www.devze.com 2023-02-24 10:57 出处:网络
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 pa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号