视图状态的Response.Redirect上消失 [英] viewstate disappears on response.redirect

查看:91
本文介绍了视图状态的Response.Redirect上消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net C#的网页我有两个文本框(开始日期和结束日期)与阿贾克斯CalendarExtenders。用户选择开始日期,然后结束日期。在选择结束日期,我结合我的网格,如下图所示;

On my asp.net c# page I have two text boxes(start and end dates) with ajax CalendarExtenders. The user selects a start date and then an end date. On selecting the end date, I bind my grid as shown below;

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

在网格我有以下code命令按钮

In the grid I have a command button with the following code

 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的数据消失。任何想法,为什么视图状态正在消失?

When the user goes to that page and clicks the back button all the selected dates and the gridview data disappears. Any ideas why the viewstate is disappearing?

推荐答案

的ViewState 属于当前

看一看:<一href=\"http://www.$c$cproject.com/Articles/37753/Access-ViewState-Across-Pages\">http://www.$c$cproject.com/Articles/37753/Access-ViewState-Across-Pages

是的,我们可以在页面访问视图状态的变量。这仅仅是
  可能的,如果跨页投递或Server.Transfer的是用来重定向
  用户到其他网页。 如果使用的Response.Redirect,则ViewState中
  不能跨页访问

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的代替或使用会话

So you could use Server.Transfer instead or use the Session.

这篇关于视图状态的Response.Redirect上消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆