|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drop down list viewstate; please HELP!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 Have you made sure your not repopulating the drop down on pastback
(IsPostBack) 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) > 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.
How to get the HtmlForm element of an ASP.NET Page?
CreateUserWizard Control Hidden Controls yield inconsistent behavior on Postbacks Automatic updating an ASPX page Can I set initial focus from server-side into textbox? HOWTO: Bring that row back into focus ... custom webcontrol : render and then get "html" result in server side Text Length Adding control to datagrid Column span datagrid header |
|||||||||||||||||||||||