Update: the clearest explanation I have found on the web as I have been struggling through this can be found here.
Maybe I just don’t understand the model of runat server terribly well. It appears the following code is always executing the if block. If the code is running on the server side I guess I can understand that it has to be stateless.
I am a seasoned non-web programmer but it appears counter intuitive to me. Will I need to create some sort of session object or pass the current state along in the URL or what?
<script runat='server'> DateTime begin; DateTime end; int iSelectedStart = 0; int iSelectedEnd = 0; int iPutName = 0; protected void Button1_Click(object sender, EventArgs e) { if (iPutName == 0) { iPutName = 1; Label1.Text = TextBox1.Text + ' you will be slecting your start and end dates.';
It looks like part of your code got cut off, but here’s the basic thing with web programming — it’s stateless. Unless, that is, you do something (use ViewState, Session, etc.) to add some state into the mix.
In your case, it looks like you want to maintain some state through refreshes of the page. Put the values you want to preserve in ViewState to keep them across postbacks to the same page. If you want to hold values across pages on your site, use Session. If you want to maintain values across visits to the site, put them in a database and tie them to a login or cookie.