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

  • SEARCH
  • Home
  • 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 6826643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:10:19+00:00 2026-05-26T22:10:19+00:00

I have that code in my page : public partial class Utworz : System.Web.UI.Page

  • 0

I have that code in my page :

    public partial class Utworz : System.Web.UI.Page
{
    private List<Codes> Codes;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.GridView1.DataSource = Codes;
        Codes = new List<Codes>();
    }

    protected void btn_AddKodManually_Click(object sender, EventArgs e)
    {
        Codes.Add(new Codes(code: this.TextBox1.Text, codeType: this.DropDownList1.SelectedValue));
        this.GridView1.DataBind();
    }
}

My page contains UpdatePanel in which I have form. I type data in this form and add to GridView.
and problem is that every time when I call Click method my Page was create new, and my variable Code also. Why this variable not save his state ?

  • 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-26T22:10:19+00:00Added an answer on May 26, 2026 at 10:10 pm

    Problem #1: The Codes variable is getting set to a new object every time the page loads. It will never have more than one code.

    Problem #2: There is nothing here to hold the value of the Codes list from page view to page view. You need to store it somehow and retrieve it every time you want to rebind. For example, create a property called Codes and store the value in the viewstate. After adding a new code, rebind the grid.

    I understand that you might expect the grid to hold it’s state, but you’re rebinding with a new object every time. Someone else might chime in here, but you may be able to restore the Codes object by calling:

    Codes = this.GridView1.Datasource

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have this code : MainPage.cs public class MainPage : System.Web.UI.Page { public string
using System; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { public void
The code public partial class Table_Traversing : System.Web.UI.Page { Table table1 = new Table();
I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class
I have a master page with the following code: public partial class MasterPage :
I am trying the following: public partial class PopUps : System.Web.UI.Page { public string
I have a simple jQuery code that runs on a web page that has
I have an asp.net web page with a ton of code that is handled
I have this code that fetches some text from a page using BeautifulSoup soup=
I have some code that I'd like to run on a page. My problem

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.