暂时传递值并保存值,...使用会话,隐藏字段,查询字符串还是其他? [英] Passing values and saving values temporarily, ... use session, hidden field, query string or other?

查看:83
本文介绍了暂时传递值并保存值,...使用会话,隐藏字段,查询字符串还是其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个基本问题...但是,我一直在选择一个解决方案而没有给予太多帮助...

考虑具有以下表格网格的页面:/FormList.aspx

选择编辑表单的位置会将用户重定向到类似/FormEdit.aspx?Id=2

的页面

我通常可以在查询字符串中传递值,因为我在FormEdit的代码后面检查了ID是否有效.但是,会话或查询字符串传递值的最佳方式?还是其他?

当用户正在编辑表单时...我通常将ID临时保存在会话中(以避免再次从URL中获取它).在用户的表单版本中,存储值的最佳方法是什么?在会话中还是在隐藏字段中?或其他?(当我想存储一个临时的DataTable时,我相信我只能使用该会话,但是当它是一个整数值时...)

提前感谢您的建议:)

解决方案

我建议不要将 Session 用于可以轻松快速地存储和查询字符串或隐藏表单字段中的内容;您似乎在这里谈论的信息非常适合查询字符串.

请注意,当有人尝试在不同选项卡中一次编辑多个表单时, Session 可能会引入错误.当他们保存一个时, Session 值将取自他们加载保存的最后一个值……可能不是您想要的,并且可能很难弄清楚这一点.

您应该做的是将formID保留在查询字符串/表单字段中,并在提交保存时再次仔细检查它的完整性.例如,确保它是一个存在的ID,并且允许他们进行编辑.

This may be a basic question... However I've just been picking a solution without giving much though to it...

Consider a page with a grid of forms: /FormList.aspx

where choosing to edit a form redirects the user to a page like: /FormEdit.aspx?Id=2

I usually am okay with passing the values in the query string, because I check in the code-behind of FormEdit that the Id is valid. Which is the best way to pass the value, though: session or query string? Or other?

While the user is editing the form... I usually save the Id temporarily in session (to avoid getting it from the url again). During the user's form edition, what is the best way to store the value? In the session or in a hidden field ? Or other? (When I want to store a temporary DataTable, I believe I can only use the session, but when it's an integer value...)

Thanks in advance for your suggestions :)

解决方案

I would suggest not to use Session for something that can easily and quickly be stored and checked in a query string or hidden form field; the information you seem to be talking about here is perfect for the query string.

Note that Session could introduce bugs when someone attempts to edit multiple forms at once in different tabs. When they save one, the Session value taken would be from the last one they loaded up to save... likely not what you will want, and it would likely be difficult to figure this out.

What you should do is persist the formID in the query string/form fields, and just double-check it for sanity when they submit the save; Make sure it's an ID that exists and that they are allowed to edit, for example.

这篇关于暂时传递值并保存值,...使用会话,隐藏字段,查询字符串还是其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆