我的VB.net tabcontainer需要保持在活动选项卡上,当我有每个提交通过response.redirect.
我怎样才能做到这一点?我需要你的回应。重定向到那里,因为它会显示主TAB容器中添加的内容。
<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
ViewState不能与Response.Redirect
一起工作。对于当前的实现,我会使用QueryString或Session来存储对活动选项卡的引用。
Response.Redirect(String.Format("{0}?tab={1}", Request.RawUrl, TabContainer1.ActiveTabIndex))
我认为你的解决方案是使用jquery将选定的选项卡保存在cookie上或当用户点击该选项卡时的任何地方并且使用jquery从cookie中获取旧的选定选项卡并使用jquery设置选定选项卡
我可以看到你正在分配viewstate值
ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
后Response.Redirect(Request.RawUrl)
此代码不可用。
首先要注意的是ViewState不与新请求一起携带(通过调用Redirect方法启动新请求)。解决方法是使用查询字符串。在RawUrl的末尾添加active选项卡作为参数,然后在页面加载时读取它。
希望有帮助,
克丽丝将活动标签索引保存在会话变量中,并在Page_Load
事件中检查Session("ActiveTabIdx")
是否为Nothing
或空,然后将TabContainer1.ActiveTabIndex
设置为Session("ActiveTabIdx")
的值。像这样:
Protected Sub SubmitCompanies_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles SubmitCompanies.Click
'Rest of code
Session("ActiveTabIdx") = TabContainer1.ActiveTabIndex
Response.Redirect(Request.RawUrl)
End Sub
Protected Sub Page_Load(ByVal Sender As Object, ByVal e as System.EventArgs) Handles Page.Load
If not ViewState("ActiveTabIdx") is Nothing Then
TabContainer1.ActiveTabIndex = Convert.ToInt32(Session("ActiveTabIdx"))
End If
End Sub
在你的SubmitCompanies_Click
之间,你在设置ViewStat
变量的值之前重定向用户!