By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,749 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,749 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
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
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;

many thanks go to any helpers
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.