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…
The
Sessionobject 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:
You can also call the
Addmethod.