Click here to Skip to main content
15,065,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
      {
          string user = Convert.ToString( Session["user"]);
          if (user != null)
          {
              signin_btn.Text = "sign out";

              lbl_email.Text = Convert.ToString(Session["user"]);
          }
          else if(user==null)
          {
              signin_btn.Text = "Sign in";

          }

      }

      protected void signin_btn_Click(object sender, EventArgs e)
      {
          string user = Convert.ToString( Session["user"]);
          if (user != null)
          {
              Session.Clear();
              Session.Abandon();
              signin_btn.Text = "Sign in";
              Response.Redirect("login.aspx");

          }
          else if (user == null)
          {
              signin_btn.Text = "sign in";
              Response.Redirect("login.aspx");

          }
      }

this my code on master page top perform login logout on a single button but here in this code erroe is that session is not abandon or its not getting clear dts y evry time i m getting signout button or if u hv any other good idea then tell me
Posted
Comments
shelby67 13-Sep-13 2:13am
   
bool value?
Omprakash Kukana 13-Sep-13 2:18am
   
what boolo value?
shelby67 13-Sep-13 2:28am
   
I assume you're going for a ToggleButton sort of thing? If so that can be done by using a bool value at class scope.

C#
ShopingCartDataContext obj = new ShopingCartDataContext();
       protected void Page_Load(object sender, EventArgs e)
       {

           if (Session["user"] != null)
           {
               signin_btn.Text = "sign out";

               lbl_email.Text = Convert.ToString(Session["Email"]);
               lbl_email.Style.Add(HtmlTextWriterStyle.Color, "White");
           }
           else if (Session["user"] == null)
           {
               signin_btn.Text = "Sign in";

           }

       }

       protected void signin_btn_Click(object sender, EventArgs e)
       {

           if (Session["user"] != null)
           {
               Session.Clear();
               Session.Abandon();
               signin_btn.Text = "Sign in";
               Response.Redirect("login.aspx");

           }
           else if (Session["user"] == null)
           {
               signin_btn.Text = "sign in";
               Response.Redirect("login.aspx");

           }
       }
   
Hi,
change your above code to following.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
          string user = Convert.ToString(Session["user"]);
          if (user != null)
          {
              signin_btn.Text = "sign out";
              lbl_email.Text = Convert.ToString(Session["user"]);
          }
          else if(user==null)
          {
              signin_btn.Text = "Sign in";
              Response.Redirect("login.aspx");
          }
    }
}

protected void signin_btn_Click(object sender, EventArgs e)
{
    string user = Convert.ToString(Session["user"]);
    if (user != null && signin_btn.Text == "sign out")
    {
        Session.Clear();
        Session.Abandon();
        signin_btn.Text = "sign in";
        Response.Redirect("login.aspx");
    }
}

Hope it helps.
   
v2
Hi,

If U have problem using session variable then probably u can use any of App_Code class with a static string in it. assign its value once user is authenticated.
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900