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 9185467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:17:01+00:00 2026-06-17T19:17:01+00:00

I have the following global List – public partial class About : System.Web.UI.Page {

  • 0

I have the following global List –

 public partial class About : System.Web.UI.Page
 {

    List<string> changes = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<string> changes = new List<string>();
        }

I am trying to add string values to changes like so –

 protected void CheckBox1_CheckedChanged(Object sender, EventArgs e)
    {

        CheckBox chk = (CheckBox)sender;
        DataListItem item = (DataListItem)chk.NamingContainer;

        TextBox txt = (TextBox)DataList1.Items[item.ItemIndex].FindControl("aliasTextBox");
        string text = txt.Text;


        changes.Add(text);

        ViewState["array"] = changes;

    }

So I am trying to store all changes made in the dataList into changes so that when a user clicks –

protected void Button5_Click(object sender, EventArgs e)
    {
        List<string> changes = (List<string>)ViewState["array"];

        foreach (string text in changes)
        {

            WebService1 ws = new WebService1();
            ws.WebMethod(text);
        }
    }

However when it comes to clicking the button, I get a null reference exception on the – changes.add(text) section. How can I store all the values in changes to be available on button click?

  • 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-06-17T19:17:03+00:00Added an answer on June 17, 2026 at 7:17 pm

    The changes that you are making to a variable will not persist after the postback. You should save the value of this list ‘changes’ to a viewstate, session or application so that you can retain the values of the list even after the postback.

    Add this code in the CheckBox1_CheckedChanged event after updating the list

    ViewState["Somename"]=changes;
    

    Add this code in the Button5_Click before accessing the list

    changes= (List<string> )ViewState["Somename"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On server I have the following class public class A { string a1 {get;
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
I have the following setup: Web.config has customErrors mode=Off Global.Application_Error() event calls a custom
I have the following classes [Serializable()] public class ColumnList { public ColumnList() { ListOfColumns
I have the following in my Puzzle.h class Puzzle { private: vector<int> puzzle; public:
I have the following structure class List < ActiveRecord::Base has_many :global_lists end class GlobalList
I have the following List: List<Map<String, String>> items = new ArrayList<Map<String, String>>(); It's populated
I have the following global in variable in file_1.pl, in package main: package main;
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I have the following code: <?php function foo($bar) { global $products; //$products = array();

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.