据说页面不可以保存变量,所以用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";
}请大家指教!!
如下是我写的一个排序的东西:
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";
}请大家指教!!
本页面用ViewState
不过资源占用比较大