什么更好,隐藏的表单字段或viewstate? [英] What's better, a hidden form field or viewstate?

查看:72
本文介绍了什么更好,隐藏的表单字段或viewstate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个页面在查询字符串中传递了一个ID。然后它使用

这个ID从数据库中提取信息并在

页面上填充控件。当页面回发后,查询字符串将不再是

,所以我需要一些方法来存储ID。


什么这是最好的方法吗?显而易见的想法是一个隐藏的形式

字段,但似乎没有一个网页控件。我只是

使用普通的HTML控件吗?


另一个想法是把ID放在viewstate中,但这个

听起来有点超过顶部,而且它有可能从视图状态下降价值




我不是想要将它存储在Session中,因为它超时。


有何评论? TIA


-

Alan Silver

(此行下方添加的任何内容都与我无关)

Hello,

I have a page that gets passed an ID in the query string. It then uses
this ID to pull info out of a database and populate controls on the
page. When the page is posted back, the query string is not going to be
there any more, so I need some way of storing the ID.

What''s the best way of doing this? The obvious thought is a hidden form
field, but there doesn''t seem to be a web control for this. Do I just
use an ordinary HTML control?

The other thought I had was to put the ID in the viewstate, but this
sounds a bit over the top, plus it has the risk that the value might be
dropped form the viewstate.

I don''t want to store it in the Session as that times out.

Any comments? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

推荐答案

如果您需要在服务器和

客户端之间传递值,则使用隐藏的表单字段。如果只需要在回发之间保持一个值,请使用

viewstate。

Eliyahu


" ; Alan Silver <人********* @ nospam.thanx>在消息中写道

新闻:1F ************** @ nospamthankyou.spam ...
A hidden form field is used if you need to pass values between server and
client. If all you need is just to persist a value between postbacks, use
viewstate.

Eliyahu

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:1F**************@nospamthankyou.spam...
你好,

我有一个页面,它在查询字符串中传递了一个ID。然后它使用此ID从数据库中提取信息并在
页面上填充控件。当页面回发后,查询字符串将不再存在,所以我需要一些存储ID的方法。

最好的方法是什么这个?显而易见的想法是一个隐藏的形式领域,但似乎没有一个网络控制。我只是使用普通的HTML控件吗?

另一个想法是将ID放在viewstate中,但这听起来有点过头,加上它可能会从视图状态中删除该值。

我不想将其存储在会话中,因为它会超时。

任何意见? TIA

-
Alan Silver
(此行下面添加的任何内容都与我无关)
Hello,

I have a page that gets passed an ID in the query string. It then uses
this ID to pull info out of a database and populate controls on the
page. When the page is posted back, the query string is not going to be
there any more, so I need some way of storing the ID.

What''s the best way of doing this? The obvious thought is a hidden form
field, but there doesn''t seem to be a web control for this. Do I just
use an ordinary HTML control?

The other thought I had was to put the ID in the viewstate, but this
sounds a bit over the top, plus it has the risk that the value might be
dropped form the viewstate.

I don''t want to store it in the Session as that times out.

Any comments? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)



Viewstate也放在一个隐藏的表单字段中,所以没有太大区别

除了viewstate更容易。


如果你让我知道还有其他问题..


干杯,

Tom Pester
Viewstate is also put in a hidden form field so there is no big difference
other than that viewstate is easier.

Let me know if you have any more questions..

Cheers,
Tom Pester
你好,
页面上填充控件。当页面被回发后,查询字符串将不再存在,所以我需要一些存储ID的方法。

什么是最好的做法这个?显而易见的想法是一个隐藏的形式领域,但似乎没有一个网络控制。我是否只使用普通的HTML控件?

另一个想法是将ID放在viewstate中,但这听起来有点过头,加上它可能会从视图状态中删除该值。

我不想将其存储在会话中,因为它会超时。

任何意见? TIA
Hello,

I have a page that gets passed an ID in the query string. It then uses
this ID to pull info out of a database and populate controls on the
page. When the page is posted back, the query string is not going to
be there any more, so I need some way of storing the ID.

What''s the best way of doing this? The obvious thought is a hidden
form field, but there doesn''t seem to be a web control for this. Do I
just use an ordinary HTML control?

The other thought I had was to put the ID in the viewstate, but this
sounds a bit over the top, plus it has the risk that the value might
be dropped form the viewstate.

I don''t want to store it in the Session as that times out.

Any comments? TIA



我同意以前的帖子,viewstate是最简单的。

如果你确实想要使用隐藏字段动态值你可以在你的表单中添加一个

''Literal''web控件并在页面中设置它的文本属性

加载到:


"< input type =''hidden''id =''hiddenField''value =''" + ID +"''>" ;;


"到******************** @ pandora。是"写道:
I agree with the previous posts, viewstate is easiest.
If you did want to use a hidden field with a dynamic value you can add a
''Literal'' web control to your form and set it''s text property during the Page
Load to:

"<input type=''hidden'' id=''hiddenField'' value=''" + ID + "''>";

"To********************@pandora.be" wrote:
Viewstate也放在一个隐藏的表单字段中,所以没有太大的区别
除了viewstate更容易。

让我知道你是否还有其他问题..

干杯,
Tom Pester
Viewstate is also put in a hidden form field so there is no big difference
other than that viewstate is easier.

Let me know if you have any more questions..

Cheers,
Tom Pester
你好,

我有一个在查询字符串中传递ID的页面。然后它使用此ID从数据库中提取信息并在
页面上填充控件。当页面被回发后,查询字符串将不再存在,所以我需要一些存储ID的方法。

什么是最好的做法这个?显而易见的想法是一个隐藏的形式领域,但似乎没有一个网络控制。我是否只使用普通的HTML控件?

另一个想法是将ID放在viewstate中,但这听起来有点过头,加上它可能会从视图状态中删除该值。

我不想将其存储在会话中,因为它会超时。

任何意见? TIA
Hello,

I have a page that gets passed an ID in the query string. It then uses
this ID to pull info out of a database and populate controls on the
page. When the page is posted back, the query string is not going to
be there any more, so I need some way of storing the ID.

What''s the best way of doing this? The obvious thought is a hidden
form field, but there doesn''t seem to be a web control for this. Do I
just use an ordinary HTML control?

The other thought I had was to put the ID in the viewstate, but this
sounds a bit over the top, plus it has the risk that the value might
be dropped form the viewstate.

I don''t want to store it in the Session as that times out.

Any comments? TIA




这篇关于什么更好,隐藏的表单字段或viewstate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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