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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:54+00:00 2026-05-26T13:43:54+00:00

Code for Property in JobQuote class: public class JobQuote { // Properties private List<string>

  • 0

Code for Property in JobQuote class:

 public class JobQuote
{
// Properties
private List<string> _jobfilenames;
public List<string> JobFileNames
{
    get
    {
        if (_jobfilenames != null)
            return _jobfilenames;
        else
        {
            _jobfilenames = new List<string>();
            return _jobfilenames;
        }
    }

    set { _jobfilenames = value; }
}

Code for Property in User Control

public JobQuote quote
{
    get 
    {
        if (ViewState["Quote"] != null)
            return (JobQuote)ViewState["Quote"];
        else
        {
            JobQuote newQuote = new JobQuote();
            return newQuote;
        }   
    }
    set { ViewState["Quote"] = value; }
}

Code in try block of UserControl where the string is not being added to the generic list of strings:

try
        {
            string filename = System.IO.Path.GetFileName(FileUploader.FileName);
            quote.JobFileNames.Add(filename); 
        }     

What am I doing wrong?

  • 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-26T13:43:54+00:00Added an answer on May 26, 2026 at 1:43 pm

    You are reading from the viewstate but you never assign.

    public JobQuote quote 
    { 
        get  
        { 
            if (ViewState["Quote"] != null) 
                return (JobQuote)ViewState["Quote"]; 
            else 
            { 
                // you only construct a new instance but you dont assign it to the viewstate
                JobQuote newQuote = new JobQuote(); 
                // add the following line to fix the problem
                // ViewState["Quote"] = newQuote;
                return newQuote; 
            }    
        } 
    

    This means that next time you refer to the quote property, a new JobQuote instance will be created rather than your old JobQuote instance being returned

    A clean way for implementing this would be:

    public JobQuote Quote
    {
        get
        {
            JobQuote result = ViewState["Quote"] as JobQuote;
            if (result == null)
            {
                result = new JobQuote();
                ViewState["Quote"] = result;
            }
    
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Property in UserControl: public JobQuote quote { get { if (ViewState[Quote] != null) return
it has a property: string Code and 10 other. common codes is list of
The language shortcut public string Code { get; set; } saves a bit of
The code: interface Property<T> { T get(); } class BoolProperty implements Property<Boolean> { @Override
I get the memberOf property for my user using this code: DirectorySearcher search =
I'm making a public property, and it keeps inserting a snippet of code. What
I've converted a public property as public variable to make code simpler and now
What's the simplest way to code against a property in C# when I have
I'm getting this error on a compact framework form. code generation for property 'inputControl'
In a .aspx web page, by setting a textbox's text property by code in

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.