Session Variable not set...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Session Variable not set...

  1. #1
    Hari Guest

    Session Variable not set...


    Hi,
    I have a strange problem. I have two buttons in the Web form. OnClick
    event of one of the buttons, I am setting a session value (Session["Login"]
    = 1 - in C#). When I try to retrieve the same session value in another button's
    onclick event, as a surprise, the session variable seem to be null. How to
    solve the problem?
    In the config file, I have the default values generated by the IDE.

    Thanks,
    Hari

  2. #2
    Sudhir Guest

    Re: Session Variable not set...


    please do tell what is Login here. Is it a Connection Object. Becuase it is
    rewcommended in .net that object containing Live references should not be
    put in Session Object.
    Sudhir

  3. #3
    Hari Guest

    Re: Session Variable not set...


    Hi,
    Thanks for the reply. Login is just a variable which is holding a login
    name(string). Is there anything to do with system/project configuration???

    Hari


    "Sudhir" <sudhirshams@indiatimes.com> wrote:
    >
    >please do tell what is Login here. Is it a Connection Object. Becuase it

    is
    >rewcommended in .net that object containing Live references should not be
    >put in Session Object.
    >Sudhir



  4. #4
    Constance J. Petersen Guest

    Re: Session Variable not set...

    Hi Hari,

    "Hari" <v_hari@indya.com> wrote in message news:3ca14d31$1@10.1.10.29...
    > I have a strange problem. I have two buttons in the Web form. OnClick
    > event of one of the buttons, I am setting a session value (Session["Login"]
    > = 1 - in C#). When I try to retrieve the same session value in another

    button's
    > onclick event, as a surprise, the session variable seem to be null. How to
    > solve the problem?


    Have you established the System.EventHandlers for each button? Did you click
    Button1 to set the session value before clicking Button2 to retrieve the value?

    This code works for me (a label and 2 buttons):

    private void InitializeComponent()
    {
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Load += new System.EventHandler(this.Page_Load);

    }

    private void Button1_Click(object sender, System.EventArgs e)
    {
    Session["Login"]= 1;
    }

    private void Button2_Click(object sender, System.EventArgs e)
    {
    Label1.Text = Session["Login"].ToString();
    }

    --
    Constance Petersen, DevX newsgroup section leader
    SoftMedia Artisans, Inc.
    http://www.smartisans.com
    For useful, usable software and Web sites
    Featured Web design: http://www.keweenawnow.com/
    --
    Please reply in the newsgroup so everyone can benefit




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center