Click here to Skip to main content
11,925,022 members (46,738 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
hi there..
in my project a user can sign in and access her home.aspx page and can hit signout link_button for signout, but when back button pressed then again home.aspx page is shown there.
I want that when signout button clicked then it go to login page and back is disabled.. How can i treat it in pagebehind C#. i mean when signout link button pressed a matthod is called that disable the back button.....
please give me some code for C# to disable back

my code is---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class MasterPage : System.Web.UI.MasterPage
protected void Page_Load(object sender, EventArgs e)
if (Session["expire"] == "True")
SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS; AttachDbFileName=|DataDirectory|\\Database.mdf; user instance=true; trusted_connection=yes");
SqlCommand cmd = new SqlCommand("SELECT fn,ln FROM signup WHERE id='"+Session["User"]+"'",con);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
Label1.Text = rd.GetString(0).ToString();
Label2.Text = rd.GetString(1).ToString();


protected void LinkButton1_Click(object sender, EventArgs e) //for Signout
Session["User"] = "";
Session["expire"] = "True";


here LinkButton1_Click for signout. As Signout Clicked session["expired"] goes true.
as sign button clicked loginpage displayed. NOW as back button is clicked so this page is loded again and session["expire"]=true checked ... so in pageload field what should i write so that back cannot load it again...
Posted 16-Aug-12 22:21pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

<script language="JavaScript">

Try this..
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

I can give you the code because i also face that problem and solve it using session.You need to clear the session of browser when you log out from your page.
After successfull login in page load event add these lines..
Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
Response.AddHeader("Pragma", "no-cache");
and then in log out button code write..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.3 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100