Response.Redirect,将 tabcontainer 保持在活动选项卡上

发布于 2024-12-08 20:15:34 字数 1301 浏览 0 评论 0原文

当我让每个提交都经过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

给不了的爱 2024-12-15 20:15:34

ViewState 无法与 Response.Redirect 一起使用。在您当前的实现中,我将使用 QueryString 或 Session 来存储对活动选项卡的引用。

Response.Redirect(String.Format("{0}?tab={1}", Request.RawUrl, TabContainer1.ActiveTabIndex)) 

ViewState won't work with Response.Redirect. With your current implementation, I would use QueryString or Session to store reference to the active tab.

Response.Redirect(String.Format("{0}?tab={1}", Request.RawUrl, TabContainer1.ActiveTabIndex)) 
楠木可依 2024-12-15 20:15:34

我认为您的解决方案是使用 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

软糯酥胸 2024-12-15 20:15:34

分配了视图状态值

ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex

之后

Response.Redirect(Request.RawUrl)

正如我所看到的,您在此代码不可访问

。首先要注意的是,ViewState 不带有新请求(通过调用 Redirect 方法启动新请求)。解决方案是使用查询字符串。在 RawUrl 末尾添加活动选项卡作为参数,然后在页面加载时读取它。

希望这有帮助,

克里斯

As I can see you are assigning viewstate value

ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex

after

Response.Redirect(Request.RawUrl)

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

悲喜皆因你 2024-12-15 20:15:34

将活动选项卡索引保存在会话变量中,并在 Page_Load 事件中检查 Session("ActiveTabIdx") 是否不 Nothing 或为空,然后设置TabContainer1.ActiveTabIndexSession("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 变量的值之前重定向用户!

Save the active tab index in say Session variable and in your Page_Load event check if Session("ActiveTabIdx") is not Nothing or empty then set the TabContainer1.ActiveTabIndex to the value of Session("ActiveTabIdx"). Something like this:

    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

Between in your SubmitCompanies_Click you are redirecting user before setting the ViewStat variable's value!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文