您可以在视图状态中存储数据集吗?我们应该吗? [英] Can you store datasets in the viewstate? Should we?

查看:76
本文介绍了您可以在视图状态中存储数据集吗?我们应该吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写用于删除数据库中的记录的脚本时,我倾向于以这种方式在

中执行:


- 删除链接将ID传递给删除.aspx页面

- delete.aspx页面查询db使用该ID检索文件

信息

- 页面显示文件信息带' '你确定要删除''

确认按钮。

- 点击所述按钮后,我删除了记录。


足够简单。


有时,我需要删除与一条记录相关的多条记录作为

以及与文件系统相关的实际文件记录。


在这种情况下,我倾向于使用这种方法:


- 删除链接将ID传递给delete.aspx页面

- delete.aspx页面使用该ID查询db来检索文件

信息

- 页面显示文件信息带有''你确定吗?你想删除''

确认对接on。

- 单击所述按钮后,我重新查询数据库以再次获取数据

- 我循环返回的数据集首先删除相关内容,

然后删除父记录


在该方法中,我查询数据库两次基本相同的数据。


查询一次更有意义,然后将数据存储在viewstate

(如果可以的话)。或者只是做一个双重查询并不是什么大问题。


因为这些是小数据集,所以此时可能是一个没有实际意义的问题,但是

供将来参考,我想了解这种

类型情况的最佳实践。


-Darrel

解决方案

" darrel" < no ***** @ nowhere.com写了留言

news:ut ************** @ TK2MSFTNGP02.phx.gbl ...


当我编写用于删除数据库中记录的脚本时,我倾向于以

这样做:



< snip>


足够简单。



是的,但是你让我想知道你是否使用ASP Classic或ASP.NET。对于

一件事,当你谈到编写脚本时,你的意思是VBScript还是

JavaScript?你肯定不会把VB.NET或C#称为脚本...... ???


好​​的,所以你谈谈ViewState,所以你必须使用ASP .NET,但为什么在

earth上你需要一个单独的页面来执行数据库写操作?这是非常糟糕的ASP经典kludge,其中ASP.NET Postback

功能旨在取代......


- delete.aspx页面使用该ID查询数据库以检索文件

信息



再次,在ASP.NET中,你会问*之前*回发


< asp:Button ID =" cmdDelete"文本= QUOT;删除" OnClick =" cmdDelete_Click()"

OnClientClick =" return confirm(''您确定要删除此

记录吗?'');" />


我想了解这类情况的最佳做法。



使用回发...


是的,但是你让我想知道你是不是''重新使用ASP Classic或ASP.NET。


首先,当你谈到编写脚本时,你的意思是VBScript

还是JavaScript?你肯定不会把VB.NET或C#称为脚本...... ???



我在写作之前没有完全考虑过这个问题。 ; o)


不,这是asp.net,我应该说功能。不是脚本。


再次,在ASP.NET中,你会在*回发


$ b之前问这个问题* $ b正确:


页面加载

按钮点击''确认''

回发删除记录


>我想了解这类情况的最佳做法。



使用回发...



我是。但这不是真正的问题。问题是我可以和/或

我应该在viewstate中存储数据集以将其从页面加载转移到

回发吗?或者我应该在回发时重新查询数据库?


-Darrel


" darrel" < no ***** @ nowhere.comwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl .. 。


我是。但这不是真正的问题。问题是我可以和/或

我应该在viewstate中存储数据集以将其从页面加载

转移到回发吗?或者我应该在回发时重新查询数据库?



摆脱额外的删除页面,你不必担心

这个......


When I write scripts for deleting records in databases, I tend to do it in
this fashion:

- delete link passes ID to a delete.aspx page
- delete.aspx page queries db using that ID to retrieve the file
information
- page displays file information with a ''are you sure you want to delete''
confirmation button.
- upon clicking said button, I delete the record.

Simple enough.

At times, though, I need to delete multiple records related to one record as
well as actual files in the filesystem related to the record.

In that case, I tend to use this method:

- delete link passes ID to a delete.aspx page
- delete.aspx page queries db using that ID to retrieve the file
information
- page displays file information with a ''are you sure you want to delete''
confirmation button.
- upon clicking said button, I requery the db to get the data again
- I loop through the dataset returned to delete the related content first,
then delete the parent record

In that method, I query the DB twice for essentially the same data.

Would it make more sense to query once, then store the data in the viewstate
(if I can). Or is it not a big deal to just do a double query.

As these are small datasets, it''s probably a moot issue at this point, but
for future reference, I''d like to understand the best practices for this
type of situation.

-Darrel

解决方案

"darrel" <no*****@nowhere.comwrote in message
news:ut**************@TK2MSFTNGP02.phx.gbl...

When I write scripts for deleting records in databases, I tend to do it in
this fashion:

<snip>

Simple enough.

Yes, but you''re making me wonder if you''re using ASP Classic or ASP.NET. For
one thing, when you talk about writing "scripts", do you mean VBScript or
JavaScript? You surely don''t refer to VB.NET or C# as "scripts"...???

OK, so you talk about ViewState, so you must be using ASP.NET, but why on
earth do you need a separate page to carry out your database writes? This is
very much the awful ASP Classic kludge which the ASP.NET Postback
functionality was designed to replace...

- delete.aspx page queries db using that ID to retrieve the file
information

Again, in ASP.NET, you would ask that question *before* the postback

<asp:Button ID="cmdDelete" Text="Delete" OnClick="cmdDelete_Click()"
OnClientClick="return confirm(''Are you sure you want to delete this
record?'');" />

I''d like to understand the best practices for this type of situation.

Use Postback...


Yes, but you''re making me wonder if you''re using ASP Classic or ASP.NET.

For one thing, when you talk about writing "scripts", do you mean VBScript
or JavaScript? You surely don''t refer to VB.NET or C# as "scripts"...???

I do when I don''t fully think about it before writing. ;o)

No, this is asp.net, I should have said functions. Not scripts.

Again, in ASP.NET, you would ask that question *before* the postback

Correct:

page loads
button click ''confirms''
postback deletes record

>I''d like to understand the best practices for this type of situation.


Use Postback...

I am. But that wasn''t really the question. The question is can I and/or
should I store a dataset in the viewstate to carry it over from page load to
the postback? Or should I just requery the DB upon postback?

-Darrel


"darrel" <no*****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

I am. But that wasn''t really the question. The question is can I and/or
should I store a dataset in the viewstate to carry it over from page load
to the postback? Or should I just requery the DB upon postback?

Get rid of the additional delete page, and you won''t have to worry about
this...


这篇关于您可以在视图状态中存储数据集吗?我们应该吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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