C# 在一个页面上加载页面之前,会话丢失,但在另一个页面上未加载

C# 在一个页面上加载页面之前,会话丢失,但在另一个页面上未加载,c#,javascript,asp.net,webforms,C#,Javascript,Asp.net,Webforms,我正在开发一个应用程序,在许多页面上使用类似的功能。我有一个屏幕,打开一个模式窗口,允许用户进行搜索。当用户单击记录时,记录名称首先保存在会话中,然后要求父窗口关闭模式,然后刷新 然后在父级的页面加载上,我进行检查,查看搜索文本会话的值,然后使用该会话搜索其他数据并填充屏幕 这个设置在我开发的第一个屏幕上运行良好,一次也没有失败。问题是,在我以完全相同的方式设置的另一个屏幕上,在父窗口的页面加载上检查会话值时,它被简单地设置为NULL,我甚至将相同的代码从工作页面复制到该屏幕,因此它应该是相同的

我正在开发一个应用程序,在许多页面上使用类似的功能。我有一个屏幕,打开一个模式窗口,允许用户进行搜索。当用户单击记录时,记录名称首先保存在会话中,然后要求父窗口关闭模式,然后刷新

然后在父级的页面加载上,我进行检查,查看搜索文本会话的值,然后使用该会话搜索其他数据并填充屏幕

这个设置在我开发的第一个屏幕上运行良好,一次也没有失败。问题是,在我以完全相同的方式设置的另一个屏幕上,在父窗口的页面加载上检查会话值时,它被简单地设置为NULL,我甚至将相同的代码从工作页面复制到该屏幕,因此它应该是相同的

子窗口JS:

  <script type="text/javascript">
        function sendval() {
            window.parent.onSave(); - Just switches off a checkdirty function.
            window.parent.location.reload(); - Reloads the parent so it can get the val on page load
        }
        </script>
父窗口检查会话值(这是会话在一个页面上返回为null,而在另一个页面上返回为null的情况:

protected void Page_Load(object sender, EventArgs e)
            {
//get the session variable from the open page in order to do the search.
                if (Session["CustTypeVal"] != null)
                {
                    //The method you need to run after refresh
                    SearchInvAddr((string)Session["CustTypeVal"]);
                    //Remove the session after
                    Session.Remove("CustTypeVal");
                }
}
如果您能在这方面提供帮助,我将不胜感激。

请在此处输入您的代码

protected void Page_Load(object sender, EventArgs e)
            {
//get the session variable from the open page in order to do the search.
                if (Session["CustTypeVal"] != null)
                {
                    //The method you need to run after refresh
                    SearchInvAddr((string)Session["CustTypeVal"]);
                    //Remove the session after
                    Session.Remove("CustTypeVal");
                }
}
如果这是您的第一页,并且您在第二页上有完全相同的代码,那么会话值将不再存在,因为

Session.Remove("CustTypeVal");

如果您使用的是会话值,则在您注销之前不必清除它们,因此没有必要删除它们,除非它可能被用于违反安全性。

您可以共享更多的代码吗?我在下面添加了我的回答,但更多的代码将有助于更完整地回答您的问题未正确获取会话值将很有帮助。
protected void Page_Load(object sender, EventArgs e)
            {
//get the session variable from the open page in order to do the search.
                if (Session["CustTypeVal"] != null)
                {
                    //The method you need to run after refresh
                    SearchInvAddr((string)Session["CustTypeVal"]);
                    //Remove the session after
                    Session.Remove("CustTypeVal");
                }
}
Session.Remove("CustTypeVal");