Best Practice - Question

P

Prince

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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top