我有一个带有在服务器上运行的表的aspx页面。我写了一个代码在表中插入一行,如下面的代码所示。我想保存现在更新的aspx页面(即,如果可能,覆盖当前的),以便下次访问该页面时,所有信息都显示出来。我不想使用数据库来存储此信息,因为这只是临时的,我的托管包不支持数据库。请帮忙。
以下是我的代码:
Dim trow As New HtmlTableRow
Dim tcell As New HtmlTableCell
tcell.InnerText = "Code: " & TextBox1.Text & ". Weight: " & TextBox2.Text & ". Date: " & Now
trow.Cells.Add(tcell)
trow.Cells.Add(tcell)
Table.Rows.Add(trow)
TextBox1.Text = ""
TextBox2.Text = ""
'Save the aspx page
Me.SaveControlState()
Me.SaveViewState()
答案 0 :(得分:1)
您可以将数据保存在Cookie中。试试这个。
Writing a cookie.
HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;
// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddYears(50); // For a cookie to effectively never expire
// Add the cookie.
Response.Cookies.Add(myCookie);
Response.Write("<p> The cookie has been written.");
阅读cookie
HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];
// Read the cookie information and display it.
if (myCookie != null)
Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value);
else
Response.Write("not found");
答案 1 :(得分:0)
使用会话:
访问值:
System.Web.HttpContext.Current.Session(“MyVariable”).ToString()
设置值:
System.Web.HttpContext.Current.Session(“MyVariable”) = “NewValue”