I put a linkbutton control named as "Logout" on my webpage with VS 2010. When users press the "Logout" linkbutton , I want the system to do two things. First is to trigger a server side click event to do some things such clear all session variables etc.. Second is to redirect to user to another page such logon.aspx
So I wrote following codes
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LinkButton1.PostBackUrl = "LogOn.aspx";
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session.Abandon();
....
....
}
But when the programs runs , any user clicks the linkbutton.The codes of LinkButton1_Click never be executed, because the page has already been redirect to Logon.aspx page and never do the LinkButton1_Click()
My Question is why LinkButton1 offers PostBackUrl property and server-side click event , but it seems that they don't cooperate very well ~
This is because by setting the PostBackUrl you are saying that when the button is clicked that you want it to post to the LogOn.aspx page rather than posting back to itself. Since you are posting to LogOn.aspx you will never trigger the event.
Instead, you should use some type of redirect in your button click after your sesion.abandon.