views:

20

answers:

2

Please bare with me, I'm very new to asp.net.

I'm building a web app that to build a report, but there are too many arguments to give each one a name, and I want to save them indexed by numbers so I can handle them with loops later on throughout the application.

However, I'm getting an index out of range on the very first session item(0)...as I understand it, I don't have to instantiate a session myself and this should work right?

        Session[0] = txtComplianceCaseID.Text;
        Session[1] = ddlState.SelectedValue;
        Session[2] = txtActingSupervisor.Text;
        Session[3] = ddlRiskTolerance.SelectedValue;

etc...

+2  A: 

The Session object is a string dictionary; you should store objects in it with string keys.

Writing Session[0] will get or set the first item in session state.
Since Session state starts empty, it throws an exception.

Instead, you should use strings, like this:

Session["Compliance ID"] = txtComplianceCaseID.Text;
Session["State"] = ddlState.SelectedValue;
Session["Supervisor"] = txtActingSupervisor.Text;
Session["Risk Tolerance"] = ddlRiskTolerance.SelectedValue;

You can also call the Add method.

SLaks
A: 

Read more about Asp.net Session Object and how to fill it with information here

Younes
That's VS2003. You should find a newer link.
SLaks
Still works the same way. You can use the Add method and work with a "key", "value" pair...
Younes