在使用EnableviewState ="true"时感到困惑.

编程入门 行业动态 更新时间:2024-10-27 13:33:04
本文介绍了在使用EnableviewState ="true"时感到困惑.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

伙计们 我有2页. Page_1和Page_2. 在Page_1中,我EneableViewstate="true"位于页面顶部. Page_1的链接也重定向到Page_2. 下面是Page_1的Page_Load()代码.

Hi Guys I have 2 pages. Page_1 and Page_2. In Page_1 I EneableViewstate="true" on top of the page. Also Page_1 has a link that redirects to Page_2. the code for Page_Load() of Page_1 is below.

if (!Page.IsPostBack) { loadgrdAvailableStaffOnPageLoad(); loadgrvViewAppointmentsOnPageLoad(); } else if (Page.IsPostBack) { loadgrdAvailableStaffOnPageLoadViewState(); loadgrvViewAppointmentsOnPageLoadViewState(); }

在Page_2中,我在下面的代码中有取消"按钮

In Page_2 I have button "cancel" with this code below

Response.Redirect("Page_1.aspx");// So it goes to Page_1

如果因为混淆而错了,现在纠正我. 在最初的Page_Load()上,期望应用程序位于下面的"if"语句中:

Now correct me if am wrong because am confuse. On initial Page_Load() am expecting the application to go inside this "if" statement below:

if (!Page.IsPostBack) { loadgrdAvailableStaffOnPageLoad(); loadgrvViewAppointmentsOnPageLoad(); }

然后从Page_2返回后,应用程序应该正在加载 这部分:

Then after coming back from Page_2, the application should be loading this part:

else if (Page.IsPostBack) { loadgrdAvailableStaffOnPageLoadViewState(); loadgrvViewAppointmentsOnPageLoadViewState(); }

从Page_2返回后,我该怎么做才能恢复Page_1信息?

What can I do to restore Page_1 information after coming back from Page_2??

推荐答案

ViewState仅在您停留在同一页面上时可用.如果要在页面之间导航,则需要查看其他保留信息的方法: 1.会话状态: msdn.microsoft/en-us/library/ms178581.aspx [ ^ ] 2. QueryString:使用QueryString在页面之间传递变量 [ ^ ] 如果信息比仅仅几个原始值(整数,字符串等)更复杂,我将使用会话状态.它可以让您在不同页面的请求中保留复杂的对象. ViewState is only available if you stay on the same page. If you''re navigating between pages, you''ll need to look at other methods of persisting the information: 1. Session State: msdn.microsoft/en-us/library/ms178581.aspx[^] 2. QueryString: Passing variables between pages using QueryString[^] If the information is in any way more complex than just a couple of primitive values (integer, string etc) I''d use Session State. It''ll let you persist complex objects across requests for different pages.

更多推荐

在使用EnableviewState ="true"时感到困惑.

本文发布于:2023-11-24 09:58:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624754.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:困惑   EnableviewState   quot   true

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!