469,273 Members | 1,619 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,273 developers. It's quick & easy.

Best Practice - Question

I'm doing the following but I'm not sure if there is a
more efficient way to accomplish the same thing.

In my Page_Load() method, I accessed a database and
stored the information inside a DataSet. On my webpage,
I have a DataList server control that binds to the
DataSet. The method looks something like the following:

Page_Load(){
//do the database connection plus binding
if( !this.IsPostBack ){
this.DataBind();
}
else{
this.DataListServerControl.DataBind();
}
This means that everytime the page loads, it has to
access the database then re-bind. Is this the best way
to do this?

-- Prince
Nov 18 '05 #1
1 950
Re-binding id going to have to happen, as each time the page is posted back
the classes are re-instantiated form scratch. However, you don't need to
make a round-trip to the DB for the same data each time. In general, if
you're selecting the same data over and over again, it is best to cache it.
If the lifetime of the particular data that you're working with is only the
lifetime of the page in the user's browser, you can store yuor data in a
DataTable or DataSet and store it in ViewState if it isn't too big.
Otherwise, Session State might be good, or, if the same data should be
available to all users across all pages, you may want to store it in the
Application Cache.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Prince" <pr******@cox.net> wrote in message
news:04****************************@phx.gbl...
I'm doing the following but I'm not sure if there is a
more efficient way to accomplish the same thing.

In my Page_Load() method, I accessed a database and
stored the information inside a DataSet. On my webpage,
I have a DataList server control that binds to the
DataSet. The method looks something like the following:

Page_Load(){
//do the database connection plus binding
if( !this.IsPostBack ){
this.DataBind();
}
else{
this.DataListServerControl.DataBind();
}
This means that everytime the page loads, it has to
access the database then re-bind. Is this the best way
to do this?

-- Prince

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by martin | last post: by
136 posts views Thread by Matt Kruse | last post: by
4 posts views Thread by Guy Noir | last post: by
3 posts views Thread by cbrown | last post: by
3 posts views Thread by Alan Isaac | last post: by
5 posts views Thread by Frank Millman | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.