单击“保存"按钮,如何更改asp.net文本框中的数字? [英] How to change Number in asp.net Textbox on save button click?

查看:77
本文介绍了单击“保存"按钮,如何更改asp.net文本框中的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有3个文本框的表格,只是我想保存数据,例如:在将文本保存到数据库中之后,我不想输入textbox1.text = 001(这是自动更改为002),我不想输入任何东西,在页面上都应该以001开始,第二次为002,第三次为003,例如

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

推荐答案

如果要将数据保存到数据库,为什么不保存您的数据数据库中的计数器也是如此?然后,您可以在UI中随意设置格式.不难将数字格式化为001、002,....
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,....


您可以通过声明一个类级别的静态变量来做到这一点.递增并在按钮单击事件中显示.

但是我认为这不会解决目的.那是因为如果另一个用户打开同一页面,他还将看到增加的计数.

实现这一目标的几种选择:
使用会话存储计数:会话是特定于用户的,因此将为不同的用户创建不同的会话.
ViewState:您还可以将计数存储在ViewState变量中.
Cookie:可以使用Cookie将其存储在客户端上.

Session和ViewState是很重的对象,因此我不建议在这种情况下使用它.最好的选择是:

使用隐藏字段并将值存储在其中.单击按钮时,获取值,增加,显示并保存到相同的隐藏字段中.

希望它能回答您的问题.如果您有任何疑问,请告诉我. (使用添加评论"进行回复).
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).


这篇关于单击“保存"按钮,如何更改asp.net文本框中的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆