据说页面不可以保存变量,所以用Session记录临时数据,不知对不对,还有什么好用的方法?
如下是我写的一个排序的东西:
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<script> function window.onload(){document.all('TextBoxInput').focus();}</script>");
    }
    protected void ButtonBegin_Click(object sender, EventArgs e)
    {
        int intTime = 0;
        double[] sortInput = new double[5];
        if (TextBoxInput.Text != "")
        {
            if (Session["inputTime"] != null)
                intTime = (int)Session["inputTime"];
            else
                LabelDispBegin.Text = "";
            if (Session["arraySortInput"] != null)
                sortInput = (double[])Session["arraySortInput"];
            else
                LabelDispEnd.Text = "";
            sortInput[intTime] = Convert.ToDouble(TextBoxInput.Text);
            Session["inputTime"] = intTime + 1;
            Session["arraySortInput"] = sortInput;
            LabelDisp.Text = (intTime+1).ToString();
            TextBoxInput.Text = "";
        }
        if (intTime >= 4)
        {
            foreach (double doubleTemp in sortInput)
            {
                LabelDispBegin.Text = LabelDispBegin.Text + " " + doubleTemp.ToString();
            }
            PanelInput.Visible = false;
            PanelDisp.Visible = true;
            bool testOK = false;
            double doubletemp = 0;
            while (!testOK)
            {
                testOK = true;
                for (int i = 0; i < 4; i++)
                {
                    if (sortInput[i+1] < sortInput[i])
                    {
                        doubletemp = sortInput[i];
                        sortInput[i] = sortInput[i + 1];
                        sortInput[i + 1] = doubletemp;
                        testOK = false;
                    }
                }
            }
            foreach (double doubleTemp in sortInput)
            {
                LabelDispEnd.Text = LabelDispEnd.Text + " " + doubleTemp.ToString();
            }
            Session.Remove("arraySortInput");
            Session.Remove("inputTime");
            Response.Write("<script> function window.onload(){document.all('ButtonContuine').focus();}</script>");
        }
     }
    protected void ButtonContuine_Click(object sender, EventArgs e)
    {
        PanelDisp.Visible = false;
        PanelInput.Visible = true;
        LabelDisp.Text = "1";
    }请大家指教!!

解决方案 »

  1.   

    不知道你是不是页面之间传值,session或者querystring都可以的
      

  2.   

    保存值用隐藏控件也行啊
    本页面用ViewState
    不过资源占用比较大
      

  3.   

    先不考虑页面传值的情况,web编程以前没接解过,似乎不习惯这种模式。还有就是如果在页面要求的值输入未完成就刷新或重新打开或再打开一个相同的页,那些Sessioin变量还继续有效的话那不是全乱套了?
      

  4.   

    临时数据的话,用ViewState 就可以
      

  5.   

    ViewState 还好吧,不是很占资源