如何在asp.net中的另一个页面上获取结果?

时间:2016-06-04 08:43:17

标签: asp.net

Image1.Visible = true;

Label2.Text = "Correct Ans       = " + answer.ToString();
Label3.Text = "Incorrect Ans     = " + wrong.ToString();
Label20.Text = "Total Questions  = " + count.ToString();
Label21.Text = "Score            = " + answer* 10;
Label26.Text = "Percentage       = " + Math.Round(answer / count* 100)+ " %";

answer = 0;
wrong = 0;

1 个答案:

答案 0 :(得分:0)

有很多不同的方法可以实现这一目标。我建议您阅读A Beginner's Tutorial on ASP.NET State Management并确定哪一种最适合您

这是一个使用其中三种技术的简单示例,即:

  1. 查询字符串
  2. 会话状态
  3. 缓存
  4. 设定值:

    string name = txtName.Text;
    
    //1.Session
    Session["name"] = name;
    
    //2.Cookies
    Response.Cookies["name"].Value = name;
    Response.Cookies["name"].Expires = DateTime.Now.AddDays(1);
    
    //3.Query strings
    Response.Redirect("Page2.aspx?name=" + name);
    

    读取值:

    //1.Session
    string nameFromSession = Session["name"] as string;
    //2.Cookies
    string nameFromCookie = Request.Cookies["name"].Value;
    //3.Query strings
    string nameFromQueryString = Request.QueryString["name"];