Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created one treeview using asp.net in populate method.

Master page: I have this treeview in master page to show in all pages.

+(iconimage)Football................................football id is =1.
+(iconimage)volleball................................volleyball id is =2.

iconimage = i am taking image from database (which is in byte 0xFFD8FFE000104A4649460001010.....)
using below query: "select iconimage from tablename where footballid=1"


and then i am converting it as image using drawing.image bitmap concept.

everything works fine.

the problem is , when i redirect to next page or child page, It works good. but again that select query gets invoked and shows iconimage. so, when i rediect to some other child page, again that select query gets invoked and shows iconimage in treeview.

how to avoid select query and connecting database again and again which is working the same job.

jsut for example purpose, i showed two node. like that i have 1000 node. so, for icon image (which is coming from database), it is getting ivoked everytime whenever page gets redirected across the webform.

ofcourse first time we have to take iconimage from database in master page. but how to avoid the same thing again and again.

can i save images in folder when first time we get iconimage? if it is how and how to solve this problem..Help needed.
Posted
Comments
JoCodes 23-Dec-13 23:57pm    
Persisting the query results in a viewstate is an option

You should check IsPostBack property[^] at Page Load and work accordingly.
C#
private void Page_Load()
{
    if (!IsPostBack)
    {
        // Run select query and populate the TreeView.
    }
}

So, the query will run only when Page is loaded for the first time. It would not run for every Post Back.
 
Share this answer
 
Hi Tadit, I put like that only.


private void page_load()
{
if(!ISPostBack)
{
/query.
}

}

i mentioned master page, and child page. so when you do redirect to next next page, each time the select query wiill get invoke.
 
Share this answer
 
Comments
JoCodes 23-Dec-13 23:41pm    
Dont add your comments as solution
christhuxavier 23-Dec-13 23:54pm    
okay.
Master page is designed such a way that it reloads or recreates on each postbacks. So its a normal behavior that the whole page refreshes and calls your Menu creation logic each time.

Can use ajax frameworks using update panels.
Output caching is another mechanism which can be used to prevent the DB hit each time. But it wont be useful if the Menu display is according to the User login preferences. So the other option would be using any persisting Technics such as Viewstate or session to store the query results. The images can be persisted in the folder after the first load too since the bitmap image creation will take more time .

Hope this helps you...
 
Share this answer
 
Comments
christhuxavier 24-Dec-13 3:38am    
hi JoCodes, i have used ajax frameworks using update panels only..let me try with your other suggession. Thanks a lot.
JoCodes 24-Dec-13 3:40am    
You are welcome ChristhuXavier. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900