Home All Groups Group Topic Archive Search About

Drop down list viewstate; please HELP!

Author
4 May 2005 2:10 PM
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

Author
4 May 2005 4:06 PM
Josh
Have you made sure your not repopulating the drop down on pastback
(IsPostBack)
Author
4 May 2005 4:23 PM
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

Show quoteHide quote
"Josh" <s@a.com> wrote in message
news:O$MIqNMUFHA.3532@TK2MSFTNGP09.phx.gbl...
> Have you made sure your not repopulating the drop down on pastback
> (IsPostBack)
>
Author
4 May 2005 4:28 PM
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.