Drop down list viewstate; please HELP!

D

Dylan Mines

Hi

I'm having an absolute nightmare with this problem.

I have a dropdown list of values that are pulled from my SQL database. I
simply want to select an item and write it to another table when the user
clicks the submit button.

The problem is that the selected item seems to be read after the postback so
when i'm databinding without postback i get a null reference and when i
allow postback the selected item is always the first one in the drop down
list hence it is reading after the Page Load and not maintaing its
viewstate.
I've checked a few references and this is definitely the way to do it.

If i don't pull the values from a DB and just enter an items collection for
the drop down then it works fine.

Has anyone seen this before and can they point me in the right direction to
sort it out?

Thanks,

Dylan
 
D

Dylan Mines

Hi Josh

Sure did and that's when i get the object reference not set to an intance
error.

After alot of messing about i have managed a dirty fix (or at least it seems
so to me). I've moved all my databinding code from the Page_Load method
into Page_Init. This seems to have stopped it passing a null value although
i'm sure it wouldn't be the recommended approach. what do you think?

thanks,

Dylan
 
J

Josh

Hmmm ...?

Init
LoadViewState
Load
PostbackData
Postback Events
PreRender
SaveViewState
Render
Dispose

.... so postback data is not replaced into the controls until after load, so
how putting it in the int works I've no idea.

Are you processing the details in the postback event rather than in the
page_load, that may be your problem.
 

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

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top