Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Clear session after redirect

Clear session after redirect

Scheduled Pinned Locked Moved ASP.NET
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hanzaplast
    wrote on last edited by
    #1

    hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.

    void Page_Load()
    {
    if(!Page.IsPostBack)
    {
    Session["something"] = true
    }
    }
    void Page_LoadComplete()
    {
    //i need this value between postbacks, but dont want to init it every time
    bool something = Session["something"] as bool;
    }
    /*
    i would like to have something like this
    void Page_IsChangedOrRedirected()
    {
    Session["something"] = null;
    }
    */

    B F 2 Replies Last reply
    0
    • H Hanzaplast

      hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.

      void Page_Load()
      {
      if(!Page.IsPostBack)
      {
      Session["something"] = true
      }
      }
      void Page_LoadComplete()
      {
      //i need this value between postbacks, but dont want to init it every time
      bool something = Session["something"] as bool;
      }
      /*
      i would like to have something like this
      void Page_IsChangedOrRedirected()
      {
      Session["something"] = null;
      }
      */

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      You can use

      Session.Remove("something");

      wherever you want.

      Cheers!! Brij Visit my Blog: http://brijbhushan.net
      Check my latest Article :Client Templating with jQuery

      1 Reply Last reply
      0
      • H Hanzaplast

        hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.

        void Page_Load()
        {
        if(!Page.IsPostBack)
        {
        Session["something"] = true
        }
        }
        void Page_LoadComplete()
        {
        //i need this value between postbacks, but dont want to init it every time
        bool something = Session["something"] as bool;
        }
        /*
        i would like to have something like this
        void Page_IsChangedOrRedirected()
        {
        Session["something"] = null;
        }
        */

        F Offline
        F Offline
        fjdiewornncalwe
        wrote on last edited by
        #3

        Am I understanding you correctly, that you need the value to be part of the session as long as the user is using PostBack, but on a new page load, the session value should be empty? If that is the case, then you can do this simply like this

        void Page_Load()
        {
        if(!Page.IsPostBack)
        {
        Session["something"] = true;
        }
        else
        {
        Session["something"] = false;
        }
        }

        I wasn't, now I am, then I won't be anymore.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups