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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:22:20+00:00 2026-05-13T01:22:20+00:00

I am not sure if I have asked the question correctly. Please correct me

  • 0

I am not sure if I have asked the question correctly. Please correct me if I am wrong.

Anyways, we would like to use a variable’s value on a different phases of the page’s life cycle.

So for example,

public partial class TestUserControl: UserControl{
    public TestUserControl(){
        Objects = new List<object>(){
            Property1,
            Property2,
            Property3
        };
    }

    public int Property1 { get; set; }
    public bool Property2 { get; set; }
    public string Property3 { get; set; }
    public List<object> Objects { get; set; }

    protected override OnLoad(EventArgs e){
        foreach(var item in Objects){
            Page.Controls.Add(new LiteralControl(item.ToString() + "<br/>"));
        }
    }
}

So if we say the values of Property1, Property2, Property3 are set as they were written on the tag, how could we use the properties’ values just as when needed?

That on the constructor, instead of the values of the properties will be listed down on the List, only the Properties’ names will be listed down so their current values will be used on OnLoad.

Thanks a lot.


Edit: I have adopted deerchao’s and Jon’s approach, but there seems to be another problem we will be facing… It’s like:

public partial class TestUserControl: UserControl{
    public TestUserControl(){
        Objects = List<Func<object>>{
            () => Property1,
            () => Property2,
            () => Property3
        };
    }

    public int Property1 { get; set; }
    public bool Property2 { get; set; }
    public string Property3 { get; set; }
    public List<Func<object>> Objects { get; set; }

    protected override OnLoad(EventArgs e){
        foreach (var item in Objects) {
            //Here is the problem... can we get the variable name using this approach?
            //We have tried some other ways like reflection and expressions but to no avail. Help please =)
            string key = GetVariableName(item());

            string value = item() == null ? string.Empty : item().ToString();
            Page.Controls.Add(new LiteralControl(key + " : " + value + "<br/>"));
        }
    }
}
  • 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-13T01:22:20+00:00Added an answer on May 13, 2026 at 1:22 am

    You can pass variables by reference (using ref) but not properties. Additionally, the “ref-ness” is only for the duration of the method: it aliases the argument and the parameter, but if you copy the parameter value into another variable, that other variable isn’t an alias.

    It’s not really clear exactly what you want to do here, but you could use delegates instead:

        Objects = new List<Func<object>>(){
            () => Property1,
            () => Property2,
            () => Property3
        };
    

    Then:

    protected override OnLoad(EventArgs e){
        foreach(var itemRetriever in Objects){
            Page.Controls.Add(new Literal(itemRetriever().ToString() + "<br/>"));
        }
    }
    

    It’s pretty nasty though – I’d try to find an alternative design if you can.

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

Sidebar

Ask A Question

Stats

  • Questions 235k
  • Answers 235k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You call MAPC over two empty lists. How should the… May 13, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer Looks like obj was built using a different dataContext and… May 13, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer a) Your @intOutputParameter parameter is not declared as output; use:… May 13, 2026 at 6:11 am

Related Questions

I am required to compare data in a file with a column in SQL
I asked this in the users group with no response so i thought I
I have asked this question about using the a Linq method that returns one
I have asked this question earlier today but I didn't provide enough information and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.