gpt4 book ai didi

c# - viewstate 在 response.redirect 上消失

转载 作者:行者123 更新时间:2023-11-30 13:32:21 27 4
gpt4 key购买 nike

在我的 asp.net c# 页面上,我有两个带有 ajax CalendarExtenders 的文本框(开始日期和结束日期)。用户选择开始日期,然后选择结束日期。在选择结束日期时,我如下所示绑定(bind)我的网格;

 protected void calEndDate_TextChanged(object sender, EventArgs e)
{
BindGrid();
}

在网格中我有一个带有以下代码的命令按钮

 protected void gvAllRoomStatus_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Manage")
{
GridViewRow row = gvAllRoomStatus.Rows[Convert.ToInt16(e.CommandArgument)];
int BookingID = Convert.ToInt32(row.Cells[1].Text);

DataClassesDataContext context = new DataClassesDataContext();
Session["BookingID"] = BookingID;
Response.Redirect("CheckIn.aspx");
}
}

当用户转到该页面并单击后退按钮时,所有选定的日期和 GridView 数据都会消失。知道 View 状态消失的原因吗?

最佳答案

ViewState 属于当前 Page

看看:http://www.codeproject.com/Articles/37753/Access-ViewState-Across-Pages

Yes, we can access the viewstate variables across pages. This is only possible if Cross Page Posting or Server.transfer is used to redirect the user to other page. If Response.redirect is used, then ViewState cannot be accessed across pages.

因此您可以使用 Server.Transfer 或使用 Session

关于c# - viewstate 在 response.redirect 上消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14430003/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com