如何用图像问题解决asp.net中的这个大问题。 [英] how to solve this big problem in asp.net with image issue.

查看:64
本文介绍了如何用图像问题解决asp.net中的这个大问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在populate方法中使用asp.net创建了一个树视图。



母版页:我在母版页中有这个树视图,可以显示在所有页面中。



+(iconimage)足球................................足球ID = 1。

+(iconimage)volleball ............................... .volleyball id = 2。



iconimage =我从数据库中获取图像(字节为0xFFD8FFE000104A4649460001010 .....)

使用以下查询:从tablename中选择iconimage,其中footballid = 1





然后我使用绘图将其转换为图像。图像位图概念。



一切正常。



问题是,当我重定向到下一页或儿童页面,它很好用。但是再次调用select查询并显示iconimage。因此,当我重新访问其他子页面时,再次调用select查询并在treeview中显示iconimage。



如何避免选择查询并反复连接数据库这工作的工作相同。



jsut为例,我展示了两个节点。就像我有1000个节点。因此,对于图标图像(来自数据库),每当网页被重定向到网络表单时,它都会被调用。



当然我们第一次采取iconimage来自母版页中的数据库。但是如何一次又一次地避免同样的事情。



我可以在第一次获得iconimage时将图像保存在文件夹中吗?如果它是如何以及如何解决这个问题..需要帮助。

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.

推荐答案

你应该检查 IsPostBack属性 [ ^ ]在页面加载并相应地工作。 />
You should check IsPostBack property[^] at Page Load and work accordingly.
private void Page_Load()
{
    if (!IsPostBack)
    {
        // Run select query and populate the TreeView.
    }
}



所以,查询将仅在第一次加载页面时运行。它不适用于每个Post Post。


So, the query will run only when Page is loaded for the first time. It would not run for every Post Back.


嗨Tadit,我只是这样。





private void page_load()

{

if(!ISPostBack)

{

/ query。

}



}



i提到了母版页和子页面。因此,当您重定向到下一页时,每次选择查询都将被调用。
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.


主页面设计为在每次回发时重新加载或重新创建。所以它是一个正常的行为,整个页面每次刷新并调用你的菜单创建逻辑。



可以使用更新面板的ajax框架。

输出缓存是另一种可用于防止每次数据库命中的机制。但如果菜单显示符合用户登录首选项,则不会有用。因此,另一个选项是使用任何持久性技术(如Viewstate或session)来存储查询结果。由于位图图像创建需要更多时间,因此图像可以在第一次加载后保存在文件夹中。



希望这可以帮助你......
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...


这篇关于如何用图像问题解决asp.net中的这个大问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆