单击浏览器[BACK]按钮后恢复会话变量

发布于 2024-11-25 03:25:02 字数 1512 浏览 1 评论 0原文

我的浏览器 [BACK] 按钮有问题。让我解释一下。

有一个名为 ManageClient.aspx 的页面。该页面包含[子]客户端地址(子项表示您正在查看的客户端)和父客户端地址(子项继承的客户端)的地址列表。当有人单击 ManageClient.aspx 页面中查看客户端时,没有查询字符串(但我确实在此处添加了一个变量来解决我的问题)。然而,对于某些 JavaScript,有一个名为 Session("Id") 的会话变量最终在 ManageClient.aspx 页面中设置。

当用户单击 ManageClient.aspx 页面上的地址时,他们将被带到 AddressEditor.aspx 页面,并传递查询字符串中的“Id”变量来指示地址 ID。

地址编辑器中的超链接已经损坏一段时间了。这就是我的目标——修复它们,以便为正确的客户端填充 AddressEditor.aspx。因此,为了尝试解决此问题,我向 ManageClient.aspx 页面添加了一个名为“Id”的查询字符串变量。此“Id”变量表示您正在编辑的客户端的客户端 ID。此外,我还在 AddressEditor.aspx 页面中添加了一个名为“ClientId”的查询字符串变量。由于客户端 AddressEditor 与 ManageClient.aspx 页面位于同一向导工作流程中,因此我需要设置“ClientId”查询字符串参数,以便当我到达 AddressEditor.aspx 页面时,我可以设置 Session("ClientId") 会话变量,以便如果用户继续该客户端的向导,他们将处于正确的上下文中。这很好用。

不起作用的是,当用户进入 [子] 客户端的 ManageClient.aspx 页面,然后单击父客户端地址(将它们发送到父客户端上下文中的 AddressEditor.aspx),然后单击[BACK] 按钮(将它们发送回 ManageClient.aspx 页面)。我希望他们回到子客户端的上下文,而不是父客户端。我在 ManageClient.aspx Page_PreRender 事件中放置了一个断点,实际上它确实被调用了。但是当页面呈现时,页面会填充父客户端,而不是子客户端。但是,如果我突出显示 URL 栏,然后按 [ENTER],页面将呈现为子客户端(很棒),因此它必须正确地将我的会话变量填充为子客户端(但呈现不正确),但我希望它这样做当他们单击[返回]按钮时。如何修复我刚才描述的此工作流程的 ManageClient.aspx 页面?

这是 Page_PreRender 事件:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

    Dim clientId As Integer = CType(Request.QueryString("ClientId").ToString, Integer)
    If clientId > 0 Then
        Session("ClientId") = clientId
        Me.LIMSClientId = clientId
    End If

End Sub

I have an issue with the browser [BACK] button. Let me explain.

There is a page called ManageClient.aspx. That page contains an address list of both [child] client addresses (child meaning the client you're viewing), and parent client addresses (clients the child inherits from). When someone clicks to view a client in the ManageClient.aspx page, there is no query string (but I did add a variable to fix my problem here). However, with some JavaScript, there is a session variable called Session("Id") that eventually gets set in the ManageClient.aspx page.

When the user clicks on an Address on the ManageClient.aspx page, they are taken to the AddressEditor.aspx page, and an "Id" variable in the query string is passed indicating the address id.

The hyperlinks in the address editor have been broken for quite some time. That is my goal--to fix them so the AddressEditor.aspx populates for the correct client. So to attempt to fix this, I added a query string variable to the ManageClient.aspx page called "Id". This "Id" variable indicates the client id of the client you're editing. Furthermore, I also added a query string variable to the AddressEditor.aspx page called "ClientId". Because the client AddressEditor is in the same Wizard workflow as the ManageClient.aspx page, I needed to set that "ClientId" query string parameter so when I reach the AddressEditor.aspx page, I then can set the Session("ClientId") session variable so that if the user continues in the wizard for that client, they are in the correct context. This works great.

What doesn't work is when the user enters the ManageClient.aspx page for the [child] client, and then clicks on a parent client address (sending them to AddressEditor.aspx in the context of the parent client), and then clicks the [BACK] button (sending them back to the ManageClient.aspx page). I want them to be back to the context of the child client, not the parent client. I put a breakpoint in the ManageClient.aspx Page_PreRender event, and it does in fact get called. But when the page renders, the page populates with the parent client, not the child client. But if I highlight the URL bar, and hit [ENTER], the page renders as a child client (AWESOME) so it must have populated my session variable as a child client correctly (but rendered incorrectly), but I want it to do this when they clicked the [BACK] button. How do I fix the ManageClient.aspx page for this workflow I just described?

Here is the Page_PreRender event:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

    Dim clientId As Integer = CType(Request.QueryString("ClientId").ToString, Integer)
    If clientId > 0 Then
        Session("ClientId") = clientId
        Me.LIMSClientId = clientId
    End If

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

三人与歌 2024-12-02 03:25:02

这很简单。页面中的列表是在 Page_Load 中构建的,该页面在 Page_PreRender 之后调用——在其中设置会话变量。我只需将 Page_PreRender 事件中的代码放在正在构建页面中的数据列表的代码上方即可。

This was very simple. The lists in the page were being built in Page_Load which was called after Page_PreRender--where the session variable was being set. I just had to place the code I had in that Page_PreRender event above the code where the data lists in the page were being built.

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