Help - When does data post - newbie
Ok, have been doing win app programming for years, but I'm new to web programming. I'm confused on when data gets posted. I have a form with some user data that a load from a SQL Table, and I want to be able to change it and resave it. So I have, for example, a txtUsername text box, and a Submit button with a SQL Update command. I change the text of the txtUserName, and I hit submit....but when i try to load the new data into a command parameter, it still has the old data in it (for example: My name is Sean, I change it to Shaun, but in the code of my Submit button click txtUsername.Text still shows Sean). When does the data get changed? Do I have to enable AutoPostBack on my controls? Thanks.
Re: Help - When does data post - newbie
The problem is with the page postback, but not in the way you are thinking.
See the Page_Load event happens before your button click event. Since when the button click event is triggered it has to make a postback to the server. This causes the Page_Load event to fire again, resetting the change you just made.
To fix this use the Page.IsPostBack method to figure out if the page has been posted.
Example:
Code:
If Not Page.IsPostBack Then
'Your stuff to set the textbox
End If
Using this will bypass the textbox getting reset before the button click event is fired.
Re: Help - When does data post - newbie
yeah, that's it....thanks alot..... :blush:
Re: Help - When does data post - newbie
Although not a help post, I just wanted to comment on how I've taken the modes of working of web apps and win apps for granted. While the difference in working was always known, it wasn't apparent to me that they were so different. It's always "come naturally" when writing the code. I've seen a few threads like these which make me realize that the concept is entirely different. I'm not sure I went through that phase though.
<violin plays in background>