如何从一个页面导航离开时,明确会议明确、页面、会议

2023-09-10 18:19:08 作者:outsiders (局外人)

我GOOGLE了这个约1/2小时未击中的。情景是,动态脚本保存在字符串生成器,其字符串重presentation存储在会话。碰巧,当用户离开一个网页到另一个脚本[从会议]被使用注册的RegisterStartupScript。该脚本注册的页面preRender事件。所以,我想清楚了会话这个脚本,而页面导航离开BTW排除选项来创建另一个会话变量和清晰的previous之一。这是一个开销:(

I googled this about 1/2 a hour no hit's. Scenario is that, dynamic scripts are saved in string builder whose "string" representation is stored in session. It just happens that when user navigates away from one page to another the script[from session] gets registered using "RegisterStartupScript". The script is registered in PreRender event of the Page. So i would like to clear this script in session while the page navigates away btw rule out a option to create another session variable and clear previous one. It's a overhead :(

推荐答案

你为什么要在会话存储这一点,你需要在GET请求之间维持这个脚本?

Why are you storing this in Session, do you need to maintain this script in between GET requests?

如果做一回发时只有回传相关,你可以将其存储在视图状态,因为这是唯一保持不变。

If only postbacks are relevant you could store it in viewstate as this is maintained only when doing a postback.

如果你想这个字符串可用的GET请求太多,你可能要为大家介绍其中有一个标识符标识为其生成脚本的页面不同的变量。如果所请求的页不控制变量匹配则必须生成一个新的脚本。

If you want this string to be available on GET requests too you might want to introduce a different variable which has an identifier identifying the page for which the script is generated. If the requested page doesn't match the control variable you will have to generate a new script.