ASP.NET WebForms(IE模式下)JavaScript定时器无法读取Session变量并触发页面刷新的问题排查
We have an old ASP.NET WebForms site that only works in Microsoft Edge's IE Mode because of the hundreds of popup windows, often 10 per page. It needs to be rewritten, but that is a long-term project that has not been approved resources yet.
- Page 1 has a popup dialog, called Page 2.
- The popup Page 2 also has a popup dialog, called Page 3.
- Values selected on Page 3 need to update Page 1.
Page 3 writes the Session variable when a DataGrid item is selected:
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click ' Set Search Info If dgInvoice.SelectedIndex > -1 Then Session("csrWhere") = String.Format("WHERE ClaimKey = '{0}'", dgInvoice.Items(dgInvoice.SelectedIndex).Cells(15).Text) End If End Sub
I created a JavaScript timer to start as soon as Page 1 is loaded, and it looks for the Session variable to be set.
This is my Page 1 HTML:
<form id="Form1" method="post" runat="server"> <script type="text/javascript"> document.addEventListener("DOMContentLoaded", function () { setTimeout(function () { var csrWhere = '<%=Session("csrWhere")%>' if (csrWhere != '') { alert(csrWhere); location.reload(); } }, 200); }); </script>
Page 1's Page_Load event reads, uses, and clears the Session variable:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load If Session("csrWhere") IsNot Nothing Then Databind(Session("csrWhere")) Session("csrWhere") = Nothing End If ' other code
Whenever I select an item on Page 3, the Session variable is set, but Page 1 never reloads.
The JavaScript does not seem to be working. I added the alert(), but that never happens.
I recently learned in my previous question that IE Mode does not have Developer Tools, so I am having trouble debugging.
Why is the JavaScript not firing?
备注:内容来源于stack exchange,提问作者jp2code

