C#.net Viewstate [英] C# .net Viewstate

查看:70
本文介绍了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应用程序的响应时间。您应该在页面上使用
隐藏控件或 会话对象,以保持数据状态。


http://forums.asp.net/


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.

http://forums.asp.net/


这篇关于C#.net Viewstate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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