ViewState里的内容在Response.Redirect()后丢失了?

reddust 2004-01-05 05:17:35
同一个文件ModLCategroy.aspx
ViewState["BC"]="ssssss";
ViewState["SC"]="bbbbbbb";
Response.Redirect("ModLCategroy.aspx");

然后在private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
Label1.Text=ViewState["BC"].ToString();
}
}

是null怎么回事?
...全文
104 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
bitsbird 2004-04-14
  • 打赏
  • 举报
回复
我晕,过年前的题目啊,还没有揭帖呢
liuyu202 2004-04-14
  • 打赏
  • 举报
回复
可用三种方法传参数!

一、使用Querystring
二、使用Session变量
三、使用Server.Transfer
liuyu202 2004-04-14
  • 打赏
  • 举报
回复
同意 gOODiDEA(无语) !

ViewState仅在当前页有效!
lionsky3000 2004-04-14
  • 打赏
  • 举报
回复
ViewState 只针对当前的 Page 有效,转到另一页自然就没有了,就像JavaBean中的Spoce="Page"
sanniko 2004-04-14
  • 打赏
  • 举报
回复
用Response.Redirect是因为是新的请求,页面是从新load,肯定会丢失viewstate,最简单的办法是用session.
athossmth 2004-04-14
  • 打赏
  • 举报
回复
ViewState["BC"]="ssssss";
ViewState["SC"]="bbbbbbb";

然后用javascript __doPostBack函数回调。这样再接收的时候就可以收到ViewState的值了。
bsmg 2004-01-31
  • 打赏
  • 举报
回复
viewstate只对同一个“请求”有效,虽然页面还是同一个页面,但是Response.Redirect又是一个新的“请求”了,因为http头发送的内容都改变了,记得有同样的一个使用http头的方法来实现redirect功能,实际上redirect就是执行的那个功能,不过代码忘记得。
冷月孤峰 2004-01-31
  • 打赏
  • 举报
回复
viewstate只能在本页面中使用。
如果要传值的话用Response.Redirect("ModLCategroy.aspx?id=***")或session,不过session记得要用完就释放掉:session.remove("名称");
NekChan 2004-01-05
  • 打赏
  • 举报
回复
ViewState 只能在本页面中传值。
请使用Response.Redirect("ModLCategroy.aspx?id=***");
或者使用Session(ID);
stpangpang 2004-01-05
  • 打赏
  • 举报
回复
ViewState 只能在本页面中传值。ViewState(英文)是一种机制,ASP.NET 使用这种机制来跟踪服务器控件状态值。
gOODiDEA 2004-01-05
  • 打赏
  • 举报
回复
ViewState仅在当前页有效,Response.Redirect又是一个新的请求,当然会丢失了

你可以用Session或者Cookie来保存

如:

Session["BC"]="ssssss";
Label1.Text=Session["BC"].ToString();
KK4 2004-01-05
  • 打赏
  • 举报
回复
ViewState["BC"]
ViewState["SC"]
是否付有初值
net的最近面试经典试题ASP.NET面试题集合 1. 简述 private、 protected、 public、 internal 修饰符的访问权限。 答 . private : 私有成员, 在类的内部才可以访问。 protected : 保护成员,该类内部和继承类中可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空间内可以访问。 2 .列举ASP.NET 页面之间传递值的几种方式。 答. 1.使用QueryString, 如....?id=1; response. Redirect().... 2.使用Session变量 3.使用Server.Transfer 3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。 答:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i 0 && i <= 2) return 1; else return Foo(i -1) + Foo(i - 2); } } 4.C#中的委托是什么?事件是不是一种委托? 答 : 委托可以把一个方法作为参数代入另一个方法。 委托可以理解为指向一个函数的引用。 是,是一种特殊的委托 5.override与重载的区别 答 : override 与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要 Override 是进行基类中函数的重写。为了适应需要。 6.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理? 答 : this.Server.Transfer 7.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty? 答: foreach (System.Windows.Forms.Control control in this.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ; tb.Text = String.Empty ; } } 8.请编程实现一个冒泡排序算法? 答: int [] array = new int ; int temp = 0 ; for (int i = 0 ; i < array.Length - 1 ; i++) { for (int j = i + 1 ; j < array.Length ; j++) { if (array[j] < array) { temp = array ; array = array[j] ; array[j] = temp ; } } } 9.描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:不是。可以用任意类型。 10.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m [Page] 答: int Num = this.TextBox1.Text.ToString() ; int Sum = 0 ; for (int i = 0 ; i < Num + 1 ; i++) { if((i%2) == 1) { Sum += i ; } else { Sum = Sum - I ; } } System.Console.WriteLine(Sum.ToString()); System.Console.ReadLine() ; 11.用.net做B/S结构的系统,您是用几层结构来开发,每一层之间的关系以及为什么要这样分层? 答:一般为3层 数据访问层,业务层,表示层。 数据访问层对数据库进行增删查改。 业务层一般分为二层,业务表观层实现与表示层的沟通,业务规则层实现用户密码的安全等。 表示层为了与用户交互例如用户添加表单。 优点: 分工明确,条理清晰,易于调试,而且具有可扩展性。 缺点: 增加成本。 12.在下面的例子 using Sy
每每听到客户抱怨自己修改和很久的数据由于自己的一个误操作而丢失时,总想让web页面也有像window窗体一样具有提示保存的功能。所以,经过一段时间的研究以后终于实现了这个功能!============ checksave.js =======================<script language="JScript">function window::onbeforeunload(){if (typeof(document.all[‘txtCheckFlag‘]) != "undefined") // to detect whether this page need prompt the save message!{ if (event.clientY<0 && event.clientX>document.body.clientWidth-20 || event.clientY<0 && event.clientX<20 || event.altKey || event.clientY>document.body.clientHeight) event.returnValue="If you have modified some data, you need push the save button to save them. Do you want to save?";}} test
sohu
yahoo
MTR LinkButton
======== test.aspx.vb ===============Public Class test Inherits System.Web.UI.Page Protected WithEvents txtSave As System.Web.UI.WebControls.TextBox Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents txtCheckFlag As System.Web.UI.WebControls.TextBox#Region " Web Form Designer Generated Code " ‘This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init ‘CODEGEN: This method call is required by the Web Form Designer ‘Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ‘Put user code to initialize the page here txtSave.Style.Item("display") = "none" txtCheckFlag.Style.Item("display") = "none" LinkButton1.Attributes("onclick") = "javascript:return checksave(this.href)" ‘ Page.RegisterStartupScript("Prompt", "<script language=""javascript"">function pageload() { } 0 Then Page.RegisterStartupScript("warning", "<script language=""javascript"">function pageload() {if (showsavemessage(‘.‘)) " + Session("URL") + ";}function pageload() {showsavemessage(‘" + Session("URL") + "‘);} 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("warning", "<script language=""javascript"">function pageload() {" + Session("URL") + ";} 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("Redirect", "<script language=""javascript"">function pageload() {" + Session("URL") + ";}function pageload() {window.location=‘" + Session("URL") + "‘;}ViewState("flag") = True If InStr(txtCheckFlag.Text, "__doPostBack") > 0 Then Page.RegisterStartupScript("TxtSave", "<script language=""javascript"">" + Session("URL") + " 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("TxtSave", "<script language=""javascript"">function pageload() {" + Session("URL") + ";}function pageload() {window.location=‘" + Session("URL") + "‘;}Response.Redirect(Session("URL")) ‘Response.End() End If End If txtSave.Text = "" txtCheckFlag.Text = "" End Sub Private Function checkdata() As Boolean ‘check whether user really had modified the data Return True End Function Private Function savedata() As Boolean ‘do save data here! Return True End Function Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click If Me.ViewState("flag") = True Then Page.RegisterStartupScript("Redict", "<script language=""javascript"">function pageload() {window.location=‘TestNoNeedCheck.aspx‘;}function pageload() {window.location=‘TestNoNeedCheck.aspx‘;}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧