C#.net Viewstate [英] C# .net Viewstate
问题描述
我不明白为什么变量"计数"不增加:
protected void StartFind6_Click(object sender,EventArgs e)
  ;      {
int sum = int.Parse(TextVindPræmie.Text);
ViewState [" Sum"] = sum;
int count = 1;
ViewState [" Count"] = count;
if((int)ViewState [" Sum"]!= 6)
{
LabelFindSeks.Text = sum.ToString()+"不是正确的数字。你用过" + count +"尝试" ;;
count =(int)ViewState [" Count"] + 1;
}
否则b $ b LabelFindSeks.Text ="恭喜,你发现了"中的秘密号码"。 + count +"尝试" ;;
}
Viewstate是一个ASP.NET问题。你不应该太开心,因为浏览器和Web服务器之间的往返状态在两者之间的往返中被拖累,并减慢了Web应用程序的响应时间。您应该在页面上使用
隐藏控件或 会话对象,以保持数据状态。
I don't understand why the variable "count" doesn't increment:
protected void StartFind6_Click(object sender, EventArgs e)
{
int sum = int.Parse(TextVindPræmie.Text);
ViewState["Sum"] = sum;
int count = 1;
ViewState["Count"] = count;
if ((int)ViewState["Sum"]!= 6)
{
LabelFindSeks.Text = sum.ToString() + " is not the right number. You have used " + count + " attempts";
count = (int)ViewState["Count"] + 1;
}
else
LabelFindSeks.Text = "Congrats, you found the secrect number in the " + count + " attempt";
}
Viewstate is an ASP.NET issue. You shouldn't get too viewstate happy, because viewstate is dragged around between the browser and the Web server on the round trip between the two and slows the response time down for the Web application. You should use a hidden control on the page or session object to keep data in state.
这篇关于C#.net Viewstate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!