您好我正在尝试使用asp.net构建一个非常基本的测验应用程序。我有一个带有字符串数组和字符串答案的测验类。然后我尝试创建一个新的测验对象并向数组添加四个问题。将它们添加到会话中并显示在标签中的另一页上。
按钮点击
protected void Unnamed8_Click(object sender, EventArgs e)
{
Quiz one = new Quiz();
one.answer = "First";
one.questions[0] = "First";
one.questions[1] = "Second";
one.questions[2] = "Third";
one.questions[3] = "Fourth";
Session["Thequiz"] = one;
Response.Redirect("WebForm1.aspx");
}
测验课
public class Quiz
{
public string[] questions;
public string answer { get; set; }
public Quiz()
{
questions = new string[] {"First","Second","Third","Fourth"};
}
}
Display.aspx尝试删除数组的第一个元素并将其添加到标签
namespace Quiz
{
public partial class WebForm1 : System.Web.UI.Page
{
Quiz was;
protected void Page_Load(object sender, EventArgs e)
{
was = (Quiz)Session["Thequiz"];
was.answer = (string)display.Text;
}
}
}
标签是空白的,只是想知道原因。
答案 0 :(得分:1)
您可以反转标签和分配值。
display.Text = was.answer;