Sign in to follow this  
Moe

[web] ASP.Net - getting updated values from a page...

Recommended Posts

Okay, so it's been a while since I have done any sort of web programming, and I've run into something that has got me pretty well stumped. I've got a fairly simple web application with a form that shows a few basic pieces of data in a few text boxes. This form is populated by grabbing values from the query string. A user should be able to make changes to the data, then click a button on the same form that should grab the updated data off the form and updated a related record in a database. Populating the form works just fine. I'm doing that in the Page_Load event, and that seems to work just fine. What doesn't work is after the user has made some changes to the contents of the text fields and clicks the 'update' button, the code behind the button click isn't getting the updated values from the page. Instead, it is pulling the values that were on the page. I have no idea where it is even grabbing the old values from. When I step through using the debugger, it definitely shows me that it is grabbing the old values. I find this most puzzling, because I can clearly the updated values on the form. I've tried working around this by saving the values to a session variable when each field is changed (i.e.: each field's TextChanged event), then reading them back out when the button is clicked, but this is doing the same thing of grabbing the old values. I really have no idea how to get around this. It seems like such a simple thing, yet it just doesn't work. What obvious thing am I missing? Is it something to do with the order that things are done in ASP.Net (or the web in general)? My google-fu has failed to find anything like this.

Share this post


Link to post
Share on other sites
Bah, a co-worker spotted it. It was a bit of an odd mistake, but one that I should have noticed earlier.

What was happening is the page was being populated on the Page_Load event. When I was clicking on the 'update' button, it was first running the Page_Load event, then the event handler for the button. Because I wasn't checking in the Page_Load event if it was a postback, it was reloading all the data on the form from the values in the query string. This meant that it wan't necessarily using the values that were previously there on the button click event handler, but instead was reloading the data and using it. Ugh.

It's things like this that make me remember why I'm not a web developer...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this