WebControl, WSS, Session

C

chris

'm having some problems with a WebControl, Sharepoint and
SessionState. and NullReferences.

Somewhere, this method it throwing a NullReference Exception. It
began when I added the session information.

Options for null -
base - not likely - worked before SS added.

I think I handled the case of the empty session appropriately, if not
overzealously. Is there something funky about WSS and SessionState? Or
am I getting the SessionState from the wrong place?

Class Declaration: public class WebQuizControl : WebControl

The Method:
protected override void CreateChildControls()
{
base.EnsureChildControls();
if ( !isConfigured ) return;
object temp = null;
if (! HttpContext.Current.Session.IsNewSession)
temp = HttpContext.Current.Session["questionSet"];

// Does C# shortcut here? if temp == null is the castI
executed?
if ( temp == null || ( temp as ExamCreator ) == null )
{
questionSet = new ExamCreator( Association, course,
module ); // parameters are valid
HttpContext.Current.Session.Add( "questionSet",
questionSet );
}
else // Probably not in here, as it crashes on initial
load.
{
questionSet =
HttpContext.Current.Session["questionSet"] as ExamCreator;
}
foreach ( Question q in questionSet.Questions )
{
this.Controls.Add( q );
}

// [snip] .. add submit, reset etc.
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top