Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:09:27+00:00 2026-05-31T20:09:27+00:00

I am trying to write a page in asp.net to update an user object

  • 0

I am trying to write a page in asp.net to update an user object from Session state and I am running into a problem putting the object back into the Session state

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class UpdateAccount : System.Web.UI.Page
{
cAccount account;

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["account"] != null)
    {
        account = (cAccount)Session["account"];

        lblID.Text = account.AccountNumber.ToString();
        txtEmail.Text = account.Email;
        txtFirstName.Text = account.FirstName;
        txtLastName.Text = account.LastName;
        lblArtist.Text = account.Artist.ToString();

        if (account.CardNumber != "")
        {
            ddlCardType.SelectedValue = account.CardType;
            txtNumber.Text = account.CardNumber;
            ddlMonth.SelectedIndex = (account.ExpMonth - 1);
            txtExpYear.Text = account.ExpYear.ToString();
        }
        else
        {
            ddlCardType.SelectedIndex = 0;
            txtNumber.Text = "";
            ddlMonth.SelectedIndex = 0;
            txtExpYear.Text = "";
        }
    }
    else
    {
        lblID.Text = "-1";
        txtEmail.Text = "";
        txtFirstName.Text = "";
        txtLastName.Text = "";
        lblArtist.Text = "";

        ddlCardType.SelectedIndex = 0;
        txtNumber.Text = "";
        ddlMonth.SelectedIndex = 0;
        txtExpYear.Text = "";
    }
}

protected void btnUpdateUser_Click(object sender, EventArgs e)
{
    if (txtOldPass.Text == account.Password)
    {
        lblOldPass.Text = "";
        account.setDetails(txtEmail.Text, txtFirstName.Text, txtLastName.Text);
        Session["account"] = account;
        Response.Redirect("Accounts.aspx");
    }
    else
    {
        lblOldPass.Text = "Password Incorrect";
    }

}
}

This is the code i am using on load, and on update. These are the only spots session state is used.

EDIT

The exact problem I am getting is the updated object does not get saved to the Session State. The old one remains on page load of this page and the page I am using to display the object. The Form_Load method works the same in both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:09:28+00:00Added an answer on May 31, 2026 at 8:09 pm

    It looks like what is happening here is:

    1. User navigates to page:

      • Page_Load fires, picks up the details from the account object stored in session.
    2. User fills in form details, clicks the update user button:

      • Page_Load fires, picks up the details from the account object stored in session, overwriting the user’s entered details.
      • btnUpdateUser_Click fires, sets details based on the current values in the form controls, which by now have been set to the old values.

    So there’s nothing wrong the click event handler, but the Page_Load activity needs to handle the post back better, i.e.:

    if (!Page.IsPostBack)
    {
        if (Session["account"] != null)
        {
        .... the rest of your stuff here ....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write code to send a simple mail from asp.net page.
I'm trying to send binary data from a database over an ASP.NET page. I
I'm trying to serve a word document (docx) from an asp.net page using the
I am playing around with Asp.net MVC2 and trying to write a page which
I'm trying to write an async page in asp .net which runs a function
I'm trying to write the following code inside ASP.Net-MVC razor view but the page
I'm trying to write a web page in .NET, using C# and NHibernate 2.1.
I am trying to develop the single page in asp.net web mobile application as
I am doing a cross-domain fetch from a ASP.NET page using Jquery-JSONP My ASP.NET
ASP.NET MVC 2 I'm trying to write a view whose generic parameter is dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.