Problem With DataList Datakey

A

Anil TG

Hello,

I am developing a website for a car servicing company.In which i have a
requirement like when the user clicks a particular color the color of the
Car's image has to be changed to the new color.For that i am using
ImageButtons in a DataList.

The problem is i am getting an error message like "Object reference not
set..." when i click on the image button in the Datalist to change the color
of the car.But this happens only if the site is kept idle for a few minutes.

The error is detected in the source where i try to access the DataKey from
the DataList.What may be the cause of the problem

Please help,

Anil TG
 
S

Stan

Hello,

I am developing a website for a car servicing company.In which i have a
requirement like when the user clicks a particular color the color of the
Car's image has to be changed to the new color.For that i am using
ImageButtons in a DataList.

The problem is i am getting an error message like "Object reference not
set..." when i click on the image button in the Datalist to change the color
of the car.But this happens only if the site is kept idle for a few minutes.

The error is detected in the source where i try to access the DataKey from
the DataList.What  may be the cause of the problem

Please help,

Anil TG

It sounds like the Session is expiring. Due you know what the Session
timout is set to? It must be quite short if it only takes a few
minutes.

Also I note your use of DataKey. Have you considered binding the
CommandArgument property of the ImageButton to the required key value?
If you assign a suitable string "ChangeCarColor" say to the
CommandName property you can use the DataList.ItemCommand event to do
the processing (the e parameter will contain the CommandName and
CommandArgument values). I think you'll find this approach much more
straightforward and reliable. The trouble with things like DataKey is
you can never be sure when they are actually set during PostBack and
what event to use.
 
A

Anil TG

Thankx a lot Stan...it worked!!..:)

Stan said:
It sounds like the Session is expiring. Due you know what the Session
timout is set to? It must be quite short if it only takes a few
minutes.

Also I note your use of DataKey. Have you considered binding the
CommandArgument property of the ImageButton to the required key value?
If you assign a suitable string "ChangeCarColor" say to the
CommandName property you can use the DataList.ItemCommand event to do
the processing (the e parameter will contain the CommandName and
CommandArgument values). I think you'll find this approach much more
straightforward and reliable. The trouble with things like DataKey is
you can never be sure when they are actually set during PostBack and
what event to use.
 

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

Top