Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a form that is having 3textbox's just i want to save data for eg: in textbox1.text=001(this is automatic change to 002)after saving data into database i don't want to enter any thing, on page it should be start with 001,second time 002,third time 003 like
Posted

You can do this by declaring a class level static variable. Increment and display it in the button click event.

But I don't think it will solve the purpose. That's because if another user opens up the same page, he will also see the incremented count.

Few options to achieve this:
Use Session to store the count: Session is user specific and so there will be different session created for different user.
ViewState: You can also store the count in ViewState variable.
Cookies: May store it on the client's using cookies.

Session and ViewState are heavy objects and so I would not recommend it's use for this scenario. The best option would be:

Use a hidden field and store the value in it. On button click, get the value, increment, display and save it to the same hidden field.

Hope it answers your question. Let me know if you have any doubt. (Use Add Comment to reply).
 
Share this answer
 
If you are saving the data to database, why not save your counter in the database as well? Then you can format however you like in the UI. It is not hard to format your number as 001, 002,....
 
Share this answer
 
Comments
Ankur\m/ 31-Jul-10 0:21am    
If you save it in database, how will the counter different for every user? I think you misunderstood the question. :)
Yusuf 31-Jul-10 0:53am    
Well, I don't think he said - different for every user. Did he? The requirement as stated is it starts with 001 and it gets incremented when the data is saved. There is no user involved.
Ankur\m/ 31-Jul-10 1:19am    
But he did say, it's an ASP.NET application which made me assume that each user will have their own count.
Anyway I never meant you are wrong in your answer, I just said you probably got the question wrong.
Quite possible I may have got the question wrong as well. But since the OP has left no comment, I will assume we both are right. :)
Cheers!

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