Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am try to add variables in a form-view using Asp.net in #C but on clicking the next button it always starts back to 0 why?
Posted

1 solution

Depends - if this is ASP.NET it is likely to be one problem, for WinForms it is likely to be another.

ASP.NET:
You have to realize that each time the user talks to you server, your page is reloaded from scratch, and all variables will have the same value as when the page was first loaded. So a Button click (unless you do something about it) will start with a Page Load event, and you will reset your variables. You can get round this by reading variables from the client in the form of cookies or hidden fields, using the Session object, and / or by chcking the IsPostBack property of your page in the Load event handler.

WinForms:
This could be more complex - it's difficult yo be exact when I can't see your code. Most likely thing is that you are not handling the "Next" within the form itself, but loading a new form instance each time. The new instance will get a new set of variables, so it would start at zero.
We would need more info to help you fix this one.
 
Share this answer
 
Comments
joanne danastasi 31-Mar-13 11:08am    
how can I use postback the code is not in the page load. in fact I have nothing in it since when the page is loaded it loads a formview which is connected to an sql database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900