在事件处理程序之间保留数据集 [英] Persisting a dataset between event handlers

查看:53
本文介绍了在事件处理程序之间保留数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ASP和.NET比较陌生,无法理解这一点

这个。

我想从数据库中读取一个数据集,一次显示一行

行的信息,使用Next和Previous按钮浏览

数据集。

我读了数据集在第一个Page_Load事件即。在一个if

(!IsPostBack)条件下,但是一旦我点击按钮点击

事件就会再次消失。

有没有替代但是每次按下按钮时重新打开连接并读取整个

数据集?或者我错过了什么?

-

Dave

I''m relatively new to ASP and .NET and having trouble getting my head round
this.
I want to read a datset from a database, and display information from one
row at a time, using a Next and a Previous button to navigate through the
dataset.
I read the dataset in the first Page_Load event ie. inside an if
(!IsPostBack) condition, but it is gone again once I get to the button click
event.
Is there no alternative but to reopen the connection and read the entire
dataset every time a button is pushed? Or am I missing something?
--
Dave

推荐答案

Dave schrieb:
Dave schrieb:
我想从数据库中读取一个数据集,并一次显示一行
行的信息,使用Next和Previous按钮浏览
数据集。
我在第一个Page_Load事件中读取数据集即。在一个if
(!IsPostBack)条件下,但是当我到达按钮点击
事件后它再次消失。
I want to read a datset from a database, and display information from one
row at a time, using a Next and a Previous button to navigate through the
dataset.
I read the dataset in the first Page_Load event ie. inside an if
(!IsPostBack) condition, but it is gone again once I get to the button click
event.




你检查了吗?您的代码是在同一个请求中执行的(

数据集加载和按钮单击)?

如果单击按钮,则会启动回发并且您写了加载

只有当请求是*不是*回发时数据库条目...


Jan



Have you checked that your code is executed in the same request (both the
dataset loading and the button click)?
If you click a button a postback is initiated and you wrote that you load
the database entry only if the request is *not* a postback...

Jan


我没有读过button_click事件中的数据,我只在

Page_Load事件中读取它。

如果我在Page_Load事件中读取数据库即使它是一个回发,

然后我每次用户按下

a按钮时从数据库中读取整个记录集。我的问题是,我必须这样做,还是有更好的方法。

-

Dave

" Jan Peter Stotz"写道:
I don''t read the data in the button_click event, I only read it in the
Page_Load event.
If I read the database in the Page_Load event even when it is a postback,
then I read the whole recordset from the database every time the user pushes
a button. My question is, must I do this, or is there a better way.
--
Dave
"Jan Peter Stotz" wrote:
Dave schrieb:
Dave schrieb:
我想从数据库中读取一个数据集,并显示来自一行的信息。一次,使用Next和Previous按钮浏览
数据集。
我在第一个Page_Load事件中读取数据集,即。在一个if
(!IsPostBack)条件下,但是当我点击按钮点击
事件后它再次消失。
I want to read a datset from a database, and display information from one
row at a time, using a Next and a Previous button to navigate through the
dataset.
I read the dataset in the first Page_Load event ie. inside an if
(!IsPostBack) condition, but it is gone again once I get to the button click
event.



你有没有检查过你的代码是在同一个请求中执行(
数据集加载和按钮单击)?
如果单击一个按钮,则启动回发并且您写道,只有在请求时才加载数据库条目是*不是*回发...

Jan



Have you checked that your code is executed in the same request (both the
dataset loading and the button click)?
If you click a button a postback is initiated and you wrote that you load
the database entry only if the request is *not* a postback...

Jan



Dave写道:
是否有每次按下按钮时,别无选择,只能重新打开连接并读取整个
数据集?或者我错过了什么?
Is there no alternative but to reopen the connection and read the entire
dataset every time a button is pushed? Or am I missing something?




不。你什么都没错过。 CGI编程是无状态的。 CGI

在ASP.NET编程让你能够在某些情况下自己隐藏这个事实,但这不是其中之一。


您将需要打开与数据库的新连接,并且每次回送服务器都会返回
。您的页面在幕后发布回来

让您在OnClick处理程序中退出。你可以访问有关Form,QueryString,Cookies和Session状态的

信息。

希望你能在那里藏出足够的信息来支持你$>
重建你的DataSet。


祝你好运!


Jason Kester

Expat Software咨询服务
http://www.expatsoftware.com



Nope. You''re not missing anything. CGI programming is stateless. CGI
programming in ASP.NET gives you the ability to hide this fact from
yourself in certain cases, but this is not one of them.

You will need to open a new connection to the database with every
postback to the server. Your page is posting back behind the scenes to
drop you off at that OnClick handler. You''ll have access to the
information on the Form, QueryString, Cookies, and Session state.
Hopefully you will have stashed enough information there to enable you
to rebuild your DataSet.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com


这篇关于在事件处理程序之间保留数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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