ListBox.SelectedItem.Text is not set to an instance of object

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

Jax

I do this kind of thing all the time in applications but with ASP.NET i have
problems with selecting an item in a list box and reading that selected text
out when something like a button is pressed.
First the problem was to do with the listbox losing it's selected item, now
i've managed to keep it but whenever i want to perform some kind of
opewration i get "Reference is not set to an instance of object".
Can anyone help at all?

jax
 
I find it generally means you've made a typo on the aspx page. The id of
the control must match the name of the control on the page behind.

e.g.
protected System.Web.UI.WebControls.Label lblName;

<asp:Label id="lblName" runat="server"></asp:label>

Or perhaps you've forgotten the runat="server".

Matt
 
Back
Top