Response.Redirect,将 tabcontainer 保持在活动选项卡上
当我让每个提交都经过response.redirect 时,我的 VB.net tabcontainer 需要保持在活动选项卡上。
我怎样才能实现这个目标?我需要那里的response.redirect,因为它将显示主选项卡容器中添加的内容。
<asp:TabContainer runat="server" ActiveTabIndex="0" Height="200px"
Width="175px" ScrollBars="Auto" EnableTheming="True" Font-
Underline="False" ID="TabContainer2" EnableViewState="False"
Style="float:right; padding-left: 110px; margin-bottom: 340px;"
OnActiveTabChanged="TabContainer1_ActiveTabChanged">
Protected Sub TabContainer1_ActiveTabChanged(ByVal sender As Object,
ByVal e As EventArgs)
ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
End Sub
Protected Sub SubmitCompanies_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles SubmitCompanies.Click
*****there is more code here but for this question, it's not necessary so it has been
omitted*****
Response.Redirect(Request.RawUrl)
ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
ProductID.Value = Request.QueryString("id")
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not ViewState("ActiveTabIdx") Is Nothing Then
TabContainer1.ActiveTabIndex = Convert.ToInt32(Session("ActiveTabIdx"))
End If
End Sub
My VB.net tabcontainer needs to stay on the active tab when I have each submit going through the response.redirect.
How can I achieve this? I need that response.redirect there because it will show what has been added in the main tab container.
<asp:TabContainer runat="server" ActiveTabIndex="0" Height="200px"
Width="175px" ScrollBars="Auto" EnableTheming="True" Font-
Underline="False" ID="TabContainer2" EnableViewState="False"
Style="float:right; padding-left: 110px; margin-bottom: 340px;"
OnActiveTabChanged="TabContainer1_ActiveTabChanged">
Protected Sub TabContainer1_ActiveTabChanged(ByVal sender As Object,
ByVal e As EventArgs)
ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
End Sub
Protected Sub SubmitCompanies_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles SubmitCompanies.Click
*****there is more code here but for this question, it's not necessary so it has been
omitted*****
Response.Redirect(Request.RawUrl)
ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
ProductID.Value = Request.QueryString("id")
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not ViewState("ActiveTabIdx") Is Nothing Then
TabContainer1.ActiveTabIndex = Convert.ToInt32(Session("ActiveTabIdx"))
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ViewState 无法与 Response.Redirect 一起使用。在您当前的实现中,我将使用 QueryString 或 Session 来存储对活动选项卡的引用。
ViewState won't work with
Response.Redirect
. With your current implementation, I would use QueryString or Session to store reference to the active tab.我认为您的解决方案是使用 jquery 将选定的选项卡保存在 cookie 或用户单击选项卡时的任何位置,并使用 jquery 从 cookie 获取旧的选定选项卡并使用 jquery 设置选定的选项卡
I think your solution will be to use jquery to save the selected tab on a cookie or anyplace when the user click on the tab and also to use jquery to get the old selected tab from the cookie and set the selected tab using jquery
分配了视图状态值
之后
正如我所看到的,您在此代码不可访问
。首先要注意的是,ViewState 不带有新请求(通过调用 Redirect 方法启动新请求)。解决方案是使用查询字符串。在 RawUrl 末尾添加活动选项卡作为参数,然后在页面加载时读取它。
希望这有帮助,
克里斯
As I can see you are assigning viewstate value
after
This code is ureachable.
First note is that ViewState is not carried with new request (by calling Redirect method you start a new request). Solution is to use query string. Add active tab as a parameter at the end of your RawUrl and then read it on page load.
Hope this helps,
Kris
将活动选项卡索引保存在会话变量中,并在
Page_Load
事件中检查Session("ActiveTabIdx")
是否不Nothing
或为空,然后设置TabContainer1.ActiveTabIndex
为Session("ActiveTabIdx")
的值。像这样的事情:在您的
SubmitCompanies_Click
之间,您在设置ViewStat
变量的值之前重定向用户!Save the active tab index in say Session variable and in your
Page_Load
event check ifSession("ActiveTabIdx")
is notNothing
or empty then set theTabContainer1.ActiveTabIndex
to the value ofSession("ActiveTabIdx")
. Something like this:Between in your
SubmitCompanies_Click
you are redirecting user before setting theViewStat
variable's value!