Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Thursday, March 22, 2012

Object reference not set to an instance of an object.

When I run this code: tblMain.InnerHtml = "<tr><td>I'm sorry, you did not fill out one or more required "+
"fields (Title and or description). Please <a href=\"javascript:history.go(-1)\">go back</a> "+
"try again.</td></tr>";
tblMain is a HtmlTable which is defined as protected at the top and is set to runat server :confused: Any ideas? It's in C# in case you'd not noticed :)

ThanksOriginally posted by TomGibbons
tblMain is a HtmlTable which is defined as protected at the top ...

Thanks

But has it been instanciated? Defining is one thing, but it doesn't do much good until the instance is actualy created.

TG
I've never tried to do that as i'd say the majority of the time there will always be a better way of doing that sort of thing but anyway..... I just tried the same thing and get a different error message'HtmlTable' does not support the InnerHtml property. are you certain that this is the point where your code is failing?
Originally posted by Fishcake
I've never tried to do that as i'd say the majority of the time there will always be a better way of doing that sort of thing but anyway..... I just tried the same thing and get a different error message'HtmlTable' does not support the InnerHtml property. are you certain that this is the point where your code is failing? Ah, I wasn't getting that error message. Either way, I've gone about it a different way now and I'm getting the result I was after.

Thanks!

Object reference not set to an instance of an object.

i have a dropdownlist and 2 textbox's on my webform.
i have a table 'Areas', with 2 fields in the dataset.

In the Data properties of the DDL i have its DataTextField set to the
field 'areaName', and its DataValueField set to the other field
'areaID'.

When i select an item from the DDL i want the 'areaName' to go into
textBox1 and the 'areaID' to go into textbox2.

when i try get the the selected value:
TextBox1.Text = DropDownList1.SelectedValue
which works, gives me the areaName.

however when i try get the other field, areaID :
TextBox2.Text = DropDownList1.SelectedItem.Text
i get the error :
Object reference not set to an instance of an object.

can anyone tell me what exactly this error means, please?may be u hav same areaid for more than one records.
chek select statement.

Object reference not set to an instance of an object.

i have a webform with a dropdownlist and 2 textboxes. it has a dataset
with a table with 2 fields, 'areaID' and 'areaName'.

in the Data properties window of the DDL, i have the DataTextField set
to areaName, and the DataValueField set to areaID.

when an item is selected from the DDL i need the areaName to go in one
textbox and areaID to go in another.

this line to get the areaName works fine:
TextBox1.Text = DropDownList1.SelectedValue

but when i try get the areaID field:
TextBox1.Text = DropDownList1.SelectedItem.Text

i get the following error:
Object reference not set to an instance of an object.

can anyone tell me what exactly this error means and how to fix it
please? my head is wrecked from this.The message means one of the values participating in the statement is null.
Set a breakpoint on the line and see which value is null.

Eliyahu

<somersbar@.yahoo.com> wrote in message
news:1142956097.198040.293670@.i40g2000cwc.googlegr oups.com...
>i have a webform with a dropdownlist and 2 textboxes. it has a dataset
> with a table with 2 fields, 'areaID' and 'areaName'.
> in the Data properties window of the DDL, i have the DataTextField set
> to areaName, and the DataValueField set to areaID.
> when an item is selected from the DDL i need the areaName to go in one
> textbox and areaID to go in another.
> this line to get the areaName works fine:
> TextBox1.Text = DropDownList1.SelectedValue
> but when i try get the areaID field:
> TextBox1.Text = DropDownList1.SelectedItem.Text
> i get the following error:
> Object reference not set to an instance of an object.
> can anyone tell me what exactly this error means and how to fix it
> please? my head is wrecked from this.

Friday, March 16, 2012

Object reference not set to an instance of an object.

i have a webform with a dropdownlist and 2 textboxes. it has a dataset
with a table with 2 fields, 'areaID' and 'areaName'.

in the Data properties window of the DDL, i have the DataTextField set
to areaName, and the DataValueField set to areaID.

when an item is selected from the DDL i need the areaName to go in one
textbox and areaID to go in another.

this line to get the areaName works fine:
TextBox1.Text = DropDownList1.SelectedValue

but when i try get the areaID field:
TextBox1.Text = DropDownList1.SelectedItem.Text

i get the following error:
Object reference not set to an instance of an object.

can anyone tell me what exactly this error means and how to fix it
please? my head is wrecked from this.Usually that error means that you have tried to assign a value to an object
that has been declared but not initialised e.g.

TextBox MyTextBox;
MyTextBox.Text = "SomeWords";

"bazzer" wrote:

> i have a webform with a dropdownlist and 2 textboxes. it has a dataset
> with a table with 2 fields, 'areaID' and 'areaName'.
> in the Data properties window of the DDL, i have the DataTextField set
> to areaName, and the DataValueField set to areaID.
> when an item is selected from the DDL i need the areaName to go in one
> textbox and areaID to go in another.
> this line to get the areaName works fine:
> TextBox1.Text = DropDownList1.SelectedValue
> but when i try get the areaID field:
> TextBox1.Text = DropDownList1.SelectedItem.Text
> i get the following error:
> Object reference not set to an instance of an object.
> can anyone tell me what exactly this error means and how to fix it
> please? my head is wrecked from this.
>
Nothing has been selected in the list.

DropDownList1.SelectedItem is null (nothing). SelectedValue will
return "" if nothing is selected so it appears to be working but is
probably not pulling the value you expect.

If you changed TextBox1.Text = DropDownList1.SelectedValue to
TextBox1.Text = DropDownList1.SelectedItem.Value, the exception should
move to this line.

The question is why is nothing selected? Have fun.

Object reference not set to an instance of an object.

i have a webform with a dropdownlist and 2 textboxes. it has a dataset
with a table with 2 fields, 'areaID' and 'areaName'.
in the Data properties window of the DDL, i have the DataTextField set
to areaName, and the DataValueField set to areaID.
when an item is selected from the DDL i need the areaName to go in one
textbox and areaID to go in another.
this line to get the areaName works fine:
TextBox1.Text = DropDownList1.SelectedValue
but when i try get the areaID field:
TextBox1.Text = DropDownList1.SelectedItem.Text
i get the following error:
Object reference not set to an instance of an object.
can anyone tell me what exactly this error means and how to fix it
please? my head is wrecked from this.Usually that error means that you have tried to assign a value to an object
that has been declared but not initialised e.g.
TextBox MyTextBox;
MyTextBox.Text = "SomeWords";
"bazzer" wrote:

> i have a webform with a dropdownlist and 2 textboxes. it has a dataset
> with a table with 2 fields, 'areaID' and 'areaName'.
> in the Data properties window of the DDL, i have the DataTextField set
> to areaName, and the DataValueField set to areaID.
> when an item is selected from the DDL i need the areaName to go in one
> textbox and areaID to go in another.
> this line to get the areaName works fine:
> TextBox1.Text = DropDownList1.SelectedValue
> but when i try get the areaID field:
> TextBox1.Text = DropDownList1.SelectedItem.Text
> i get the following error:
> Object reference not set to an instance of an object.
> can anyone tell me what exactly this error means and how to fix it
> please? my head is wrecked from this.
>
Nothing has been selected in the list.
DropDownList1.SelectedItem is null (nothing). SelectedValue will
return "" if nothing is selected so it appears to be working but is
probably not pulling the value you expect.
If you changed TextBox1.Text = DropDownList1.SelectedValue to
TextBox1.Text = DropDownList1.SelectedItem.Value, the exception should
move to this line.
The question is why is nothing selected? Have fun.

Object reference not set to an instance of an object.

i have a webform with a dropdownlist and 2 textboxes. it has a dataset
with a table with 2 fields, 'areaID' and 'areaName'.
in the Data properties window of the DDL, i have the DataTextField set
to areaName, and the DataValueField set to areaID.
when an item is selected from the DDL i need the areaName to go in one
textbox and areaID to go in another.
this line to get the areaName works fine:
TextBox1.Text = DropDownList1.SelectedValue
but when i try get the areaID field:
TextBox1.Text = DropDownList1.SelectedItem.Text
i get the following error:
Object reference not set to an instance of an object.
can anyone tell me what exactly this error means and how to fix it
please? my head is wrecked from this.The message means one of the values participating in the statement is null.
Set a breakpoint on the line and see which value is null.
Eliyahu
<somersbar@.yahoo.com> wrote in message
news:1142956097.198040.293670@.i40g2000cwc.googlegroups.com...
>i have a webform with a dropdownlist and 2 textboxes. it has a dataset
> with a table with 2 fields, 'areaID' and 'areaName'.
> in the Data properties window of the DDL, i have the DataTextField set
> to areaName, and the DataValueField set to areaID.
> when an item is selected from the DDL i need the areaName to go in one
> textbox and areaID to go in another.
> this line to get the areaName works fine:
> TextBox1.Text = DropDownList1.SelectedValue
> but when i try get the areaID field:
> TextBox1.Text = DropDownList1.SelectedItem.Text
> i get the following error:
> Object reference not set to an instance of an object.
> can anyone tell me what exactly this error means and how to fix it
> please? my head is wrecked from this.
>