上按一下按钮递增变量在ASP.net [英] Incrementing variables in ASP.net on button click
问题描述
我是新来asp.net。我创建使用VB.net一个ASP.net网站。因此,这里是我的问题。
I am new to asp.net. I am creating a ASP.net website using VB.net. So here's my problem
Dim myCounter as Integer = 0
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Button1.Click
myCounter = myCounter + 1
Label1.Text = myCounter.ToString()
end Sub
正如预期的那样,我总是得到标签文本为0每次点击的按钮。如何创建全局变量并增加它。
As expected I always get Label Text as 0 each time click the button. How to I create global variable and increment it.
推荐答案
@Rex M的使用视图状态的建议是不错的。
@Rex M's suggestion for using Viewstate is good.
如果计数器不敏感信息或东西你担心与他人篡改,这里有一个更简单的想法:
If the counter is not sensitive information or something you're worried about someone tampering with., here's an easier idea:
您也可以使用< ASP:HiddenField>
并存储该值在那里。然后,它会回发之间持续存在,你可以每次增加它。
You can also use an <asp:HiddenField>
and store the value there. Then it will persist between postbacks and you can increment it each time..
这篇关于上按一下按钮递增变量在ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!