.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

ASP.NET - Loading controls at one time (on application load)

Posted By: Nani     Posted Date: September 23, 2009    Points:2   Category :ASP.Net
Hi,
We are working on an ASP.NET application. It has 3- 4 forms displaying country list dropdown. Here we would like to avoid binding these dropdowns each time by getting data from database. Instead looking for a better practice of binding it one time, say on application load/some other.

Would you please let me know how we could go head on this? Any reference link or document would be great.

Many Thanks,
Regards,
Nani

Responses
Author: Amit Mehra             
Posted Date: September 23, 2009     Points: 5   

Hi,

The Best way i can think in this scenario is to have cache object and have the Country City list in that cache object because these are the data very occasionally changed.

So set the cache expire say 1 day or depend upon whatever the time you think is the best for this data to changed.. So when data is the cache is null than go and fetch the data from database and save again into cache..

If you are looking for the code here is the sample code

if (Cache["City"] == null)
{
//Call dataBase peration

if (ds != null && ds.Tables.Count > 0)
{

//ds is your dataset
//System.Web.Caching.Cache
Cache.Insert("City", ds, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);

}
}

else
{

DataSet ds = (DataSet)Cache["TopMembers"];
if (ds != null && ds.Tables.Count > 0)
{
//Bind to dropdownlist
}
}


In the above example i have the cache expiration is 30 min you can change according to your need

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend