asp ajax慢跑 [英] asp ajax slow running

查看:46
本文介绍了asp ajax慢跑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我想在网站上使用ajax。但它是如此缓慢,我认为我的方式是错误的。我在数据库中有一个名为student的表,在Page_Load方法中我编写了下面的代码。



Hello
I want to use ajax in a website. But it is so slow and i think i'm in wrong way. I have a table with name student in database and in Page_Load method i wrote the code below.

protected void Page_Load(...)
{

   var students = from std in database.students
                  select std;

   foreach (student std in students)
        mypanel.controls.add(new myUserControl(std));

}





每个'myUserControl'都有一个值为accept的按钮,按钮位于AJAX UpdatePanel中。当用户单击此按钮时,数据库中的学生记录的接受字段将更改,按钮的背景将变为绿色。但在事件发生之前,Page_Load运行。 Page_Load中的代码需要很长时间才能执行,并且每次接受点击都会很慢。有没有更好的方法(更快一些)?



Each 'myUserControl' has a button with value accept and the button is in a AJAX UpdatePanel. When user clicks this button, accept field of the student record in database will change and background of button will be green. But before the event fires, Page_Load Runs. The code that is in Page_Load wants long time to execute and it is slow for each accept click. is there a better way to do this (some faster)?

推荐答案

我想你不需要执行这个 Page_Load 代码,当事件被触发时。



所以,最好把它放在里面!IsPostBack ,因此在加载 Page 时会被触发一次,并且它不会在 UpdatePanel 按钮点击事件上执行。

I guess you don't need to execute this Page_Load code, when the event gets fired.

So, better to put it inside !IsPostBack, so that it will be fired once while loading the Page and it will not get executed on the UpdatePanel button click events.
protected void Page_Load(...)
{
   if(!IsPostBack)
   {
        var students = from std in database.students
                       select std;

        foreach (student std in students)
            mypanel.controls.add(new myUserControl(std));
   }
}


使用

Use
if(!IspostBack)
{
   var students = from std in database.students
                  select std;
   foreach (student std in students)
        mypanel.controls.add(new myUserControl(std))

}



每当你点击按钮时,所有页面都刷新,每次回发你的网格都绑定这就是为什么它很慢

并尝试使用Storedproceture或session


Whenever u R click Button Ur All Page is refresh and every time on postback ur Grid is Bind that's why it is slow
and try to use Storedproceture or session


这篇关于asp ajax慢跑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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