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?
--
DaveDave schrieb:
> 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.
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
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:
> > 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.
> 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 wrote:
> 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?
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
"=?Utf-8?B?RGF2ZQ==?=" <Dave@.discussions.microsoft.com> wrote in
news:1E22A124-ECFA-449B-A125-1C35BB7B4665@.microsoft.com:
> 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?
If it takes a long time to execute the query, you could store the entire
dataset as a session variable.
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Aargh!
Please don't store datasets in the Session object.
It's far preferrable to use the Cache object for that.
See sample at :
http://dotnethero.com/hero/Dataset/Cache.aspx?nmx=3_4
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaol
Ven, y hablemos de ASP.NET...
======================
"Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
news:Xns96BA12F5D238nntprogerscom@.127.0.0.1...
> "=?Utf-8?B?RGF2ZQ==?=" <Dave@.discussions.microsoft.com> wrote in
> news:1E22A124-ECFA-449B-A125-1C35BB7B4665@.microsoft.com:
>> 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?
> If it takes a long time to execute the query, you could store the entire
> dataset as a session variable.
>
> --
> Lucas Tam (REMOVEnntp@.rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/
Thanks Jason, and eveyone else. That's what I thought. I gather from my
reading that the database engines are pretty good at caching, so there
shouldn't be a huge performance hit.
--
Dave
"jasonkester" wrote:
> Dave wrote:
> > 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?
> 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
>
Now THAT'S useful information. I realised using the Session object wasn't a
good idea, but I didn't know about the cache object. I'll look for more
information on that. Thanks.
--
Dave
"Juan T. Llibre" wrote:
> Aargh!
> Please don't store datasets in the Session object.
> It's far preferrable to use the Cache object for that.
> See sample at :
> http://dotnethero.com/hero/Dataset/Cache.aspx?nmx=3_4
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Espa?ol
> Ven, y hablemos de ASP.NET...
> ======================
> "Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
> news:Xns96BA12F5D238nntprogerscom@.127.0.0.1...
> > "=?Utf-8?B?RGF2ZQ==?=" <Dave@.discussions.microsoft.com> wrote in
> > news:1E22A124-ECFA-449B-A125-1C35BB7B4665@.microsoft.com:
> >> 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?
> > If it takes a long time to execute the query, you could store the entire
> > dataset as a session variable.
> > --
> > Lucas Tam (REMOVEnntp@.rogers.com)
> > Please delete "REMOVE" from the e-mail address when replying.
> > http://members.ebay.com/aboutme/coolspot18/
>
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in news:#UV2KdvpFHA.2904
@.tk2msftngp13.phx.gbl:
> Aargh!
> Please don't store datasets in the Session object.
> It's far preferrable to use the Cache object for that.
> See sample at :
> http://dotnethero.com/hero/Dataset/Cache.aspx?nmx=3_4
Isn't the cache global?
So if the data is only pertient to one user, it's easier to store it in a
session variable than in the cache.
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
According to what I've read since my last post, the cache is in the
application domain, ie. it behaves like the Application object, not like the
Session oibject, which means there is only one for all the users of the
application. I'm not exactly sure of the difference between the Application
object and the Cache object, but I think the Cache is more efficient -
there's lots of material out there. It was no use to me because it is in the
Application domain.
--
Dave
"Lucas Tam" wrote:
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in news:#UV2KdvpFHA.2904
> @.tk2msftngp13.phx.gbl:
> > Aargh!
> > Please don't store datasets in the Session object.
> > It's far preferrable to use the Cache object for that.
> > See sample at :
> > http://dotnethero.com/hero/Dataset/Cache.aspx?nmx=3_4
> Isn't the cache global?
> So if the data is only pertient to one user, it's easier to store it in a
> session variable than in the cache.
>
> --
> Lucas Tam (REMOVEnntp@.rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/
"=?Utf-8?B?RGF2ZQ==?=" <Dave@.discussions.microsoft.com> wrote in
news:66EDD071-8598-4941-8A15-475333E75923@.microsoft.com:
> According to what I've read since my last post, the cache is in the
> application domain, ie. it behaves like the Application object, not
> like the Session oibject, which means there is only one for all the
> users of the application. I'm not exactly sure of the difference
> between the Application object and the Cache object, but I think the
> Cache is more efficient - there's lots of material out there. It was
> no use to me because it is in the Application domain.
Yup, and the OP seemed to want to persist data for a specific user, for a
specific transaction... so the cache object may not be the best place to
(easily) store such data.
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Lucas,
while the data might be pertinent for one user,
it will be pertinent to *every* user that visits the site.
That will result in the dataset being stored in memory
*once for each user* that accesses the page in question.
That might add up to a lot of memory resources.
OTOH, if the Cache object is used, ONE dataset
in memory will serve the needs of many visitors,
saving a lot of memory resources.
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaol
Ven, y hablemos de ASP.NET...
======================
"Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
news:Xns96BA5535F58Enntprogerscom@.127.0.0.1...
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in news:#UV2KdvpFHA.2904
> @.tk2msftngp13.phx.gbl:
>> Aargh!
>>
>> Please don't store datasets in the Session object.
>> It's far preferrable to use the Cache object for that.
>>
>> See sample at :
>>
>> http://dotnethero.com/hero/Dataset/Cache.aspx?nmx=3_4
> Isn't the cache global?
> So if the data is only pertient to one user, it's easier to store it in a
> session variable than in the cache.
> --
> Lucas Tam (REMOVEnntp@.rogers.com)
Dave schrieb:
> 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.
You can avoid reloading the data if you include it into the viewstate,
which should be done by default. But now the data will be inserted into the
HTML response twice (one time the visible text and the second time in the
see hidden viewstate input control), so this should not be done if you want
to display large amounts of data from the database.
Jan
0 comments:
Post a Comment