ASP.NET ListBox.SelectedItem.Text or .Value = null on postback?

  • Thread starter Thread starter Jax
  • Start date Start date
J

Jax

I have a listbox.
When the user selects an item i want to to take the text of the item and
manipulate it.
It wasn't working when autopostback was false, now it's true the event runs
but i get an error when tries to access the selecteditem property of the
listbox.
I've gone through debugger and the tasks are in the items collections but i
cant access those from the object instance.
Am i using the wrong property, do i not understand the whole postback thing?

private void lstTasks_SelectedIndexChanged(object sender, System.EventArgs
e)
{
foreach(Task t in alTasks)
{
if(t != null)
{
// next line is the one that crashes.
error message: Object reference not set to an instance of an object.

if(lstTasks.SelectedItem.Text.ToString() == t.Title)
{
this.lblTaskName.Text = t.Title;
this.txtTaskInfo.Text = t.Information;
this.cBoxWorkers.Items.Clear();
}
}
}
}

many thanks go to any helpers
jax
 
Back
Top