如何将隐藏字段从一个页面传递到另一页面?
我有一个.Net 类库。我想从一次代码隐藏页面传递一个隐藏变量,并在另一个代码隐藏页面中获取它。 请注意,我没有任何可以使用表单标签和 get/post 方法的设计页面(aspx 页面)。 我们怎样才能做到这一点?
注意:我想使用隐藏字段将值从一页传递到另一页。
I have a .Net class library. I want to pass a hidden variable from once code behind page and fetch it in another code behind page.
PLease note I dont have any design page(aspx page) where I can use form tag and get/post method.
How can we do this?
NB: I want to use hidden fields to pass value from 1 page to another.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将值保存在会话中,如下所示:
在后面的代码中执行此操作:
在其他页面中执行以下操作:
you can save the value in the Session as such:
in code behind you do this:
in your other page you do:
如果您想隐藏变量,那么您可以使用会话来存储对象。
例如,
设置会话值
获取会话值
但是请记住,会话仅持续有限的时间(这可以通过 IIS 和您的 Web 配置进行配置) 。
这里是了解会话和会话状态的好资源。
If you are wanting to keep the variable hidden then you could use a session to store your object.
E.g.,
Setting the session value
Getting the session value
Do keep in mind however, that sessions are only for a limited time (this can be configured thorugh IIS and your web configuration).
Here is a good resource to learn about sessions and session state.
您可以使用 Session 或 HttpContext.Current.Items 。如果您的值是临时变量,我建议使用 HttpContext.Current.Item 而不是 session,因为一旦当前 HttpContext 消失,它就会消失,但存储在 Session 中的项目将消失在会话过期之前不会被清除。
You can use Session or HttpContext.Current.Items .If you value is a temporary variable I suggest using HttpContext.Current.Item instead of session since it will be gone as soon as current HttpContext is gone but items that are stored in Session won't be cleared until session is expired.
您可以使用会话变量吗?它们不是我的偏好,但它会满足您的需求。
善良,
丹
You could use a Session variable? They are not my preference but it would satisfy your need.
Kindness,
Dan
跨页回发怎么样(请参阅 ASP.NET 网页中的跨页回发,http://msdn.microsoft.com/en-us/library/ms178139.aspx)?从未真正使用过它,但它可能是一个选择。否则,您可以通过旧式的 Request.Form 访问隐藏的表单元素。另一种选择可能是通过将其放在母版页中来始终在每个页面上保留此隐藏元素。然后,您将其公开为公共财产,并可以根据自己的喜好获取/设置它。
What about cross-page postbacks (see Cross-Page Posting in ASP.NET Web Pages, http://msdn.microsoft.com/en-us/library/ms178139.aspx)? Never really used it, but it could be an option. Otherwise, you could access your hidden form element via the old school Request.Form . Another option could be to always have this hidden element on every page by putting it in the master page. Then you expose it as a public property and can get/set it to your heart's content.