1

Does anyone know how to write multiple values to a single session variable in C#. I have two textboxes, both will allow users to input numbers. I want to put both numbers in a single session variable. For example Textbox1 = 4, and textbox2 = 6.

Would I for example, convert both to variables then have something similar to below? If anyone could help, I would greatly appreciate it. Thanks.

Session["AppNum_Session"] = txtbox_var1, txtbox_var2;
2
  • 2
    Why do you want to do that? Commented Sep 8, 2015 at 14:22
  • 3
    Keep your values in arrays and assign this array to session. You can retrive then using arr[0], arr[1] like this. Commented Sep 8, 2015 at 14:22

1 Answer 1

1

Create a class and add to session.

public class Values
{
   public int value_1 { set; get; }
   public int value_2 { set; get; }
}

Session["values"] = new Values() { value_1 = 1, value_2 = 2 };

Then when you want get the class use this:

Values values = (Values)Session["values"];
lbltest.Text = values.value_1.ToString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.