Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax
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));
 
}
 
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)?
Posted 14-Jun-13 20:15pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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));
   }
}
Comments
shahriyar g at 15-Jun-13 6:19am
   
But the button that loads in foreach line is in 'myUserControl' (last line). If this line of code doesn't run the event can't fire.
Tadit Dash at 15-Jun-13 13:17pm
   
That will run for the first time when the Page will load, so what is the problem?
 
As you are adding the student to the panel controls making it as a User Control, then it will be done on first Page Load.
 
But if you go on executing the same code again and again on each event, then that is unnecessary slows down the speed.
 
Do you understand? Have you tried with IsPostBack yet?
Let me know if any questions and doubts.
shahriyar g at 15-Jun-13 19:06pm
   
Please download this file: http://s4.picofile.com/file/7805344622/WebApplication2.rar.html
 
this project has a default page and a page with name webform1. webform1 works correct but default page doesn't. in default page the code that is in webform1 generates dynamically.
Why default page doesn't work correct?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use
if(!IspostBack)
{
   var students = from std in database.students
                  select std;
   foreach (student std in students)
        mypanel.controls.add(new myUserControl(std))
 
}
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
  Permalink  
v2
Comments
shahriyar g at 15-Jun-13 10:01am
   
But the button that loads in foreach line is in 'myUserControl' (last line). If this line of code doesn't run the event can't fire.

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

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 15 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100