在使用EnableviewState ="true"时感到困惑. [英] Confused in use of 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.会话状态: http://msdn.microsoft.com/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: http://msdn.microsoft.com/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"时感到困惑.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!