【发布时间】:2012-09-07 10:12:37
【问题描述】:
我正在 asp.net 上用 C# 编写 web 项目。 从一个页面导航到另一个页面时,我想传递对象的实例。
例如我有一堂课
public partial class A: System.Web.UI.Page{
private Item item = new Item();//I have a class Item
protected void btn1_Click(Object sender,EventArgs e)
{
Response.Redirect("nextpage.aspx");//Here I want to send item object to the nextpage
}
}
我有一堂课
public partial class nextpage: System.Web.UI.Page{
Item myItem;
protected void Page_Load(object sender, EventArgs e)
{
myItem = //item sent from page A
}
}
那么,有没有办法将对象的实例从一个页面发送到另一个页面,比如通过 get 查询发送变量?
请不要推荐使用Session,由于我的算法,这不合适,因为我有很多超链接:
for (int i = 0; i < store1.items.Count(); i++) {
HyperLink h = new HyperLink();
h.Text = store1.items[i].Name;
h.NavigateUrl = "item.aspx";//here I must send items[i] when clicking at this hyperlink
this.Form.Controls.Add(h);
this.Form.Controls.Add(new LiteralControl("<br/>"));
}
因此,当用户点击超链接时,他/她必须被重定向到 item.aspx 并将相应的项目发送到该页面。
【问题讨论】:
-
这正是 Sessions 的用途。在驳回最明显的答案之前,请准确解释为什么会议不合适!
-
我有超链接,数量是可变的。我正在更新我上面的问题..
标签: c# asp.net object send instanceof