Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi all, I am a beginner asp programmer and am stuck on a problem. I have quite a long javascript code on my aspx page. It works fine on all internet browsers accept on IE. When i try to load the page on IE it takes a very long time to load(like 15 minutes) or it says ie is not responding. Is there anyway i can make the javascript run faster on ie? Any help will be much appreciated Thanking you in advnce.

here is my code:

C#
<script type="text/javascript">

function contract(control,member_number) {

var control_arr = control.split('_');

var x = parseFloat(control_arr[1]);
var y = parseFloat(control_arr[2]);

// make sure there is at least 1 member right

var next_right = document.getElementById('cell_'+(x+1)+'_'+y).innerHTML;

if (next_right == '') {
return false;
}

// end make sure

var num_down = 0;

for (i=(y+1); i<=3125; i++) {

var contents = document.getElementById('cell_'+x+'_'+i).innerHTML;

if (contents == '') {
num_down = num_down + 1;
} else {
break;

}

}

num_down = num_down + 1;

for (i=x; i<=5; i++) {

for (j=(y); j<(y+num_down); j++) {

if (!((i<=x) && (j==y))) {

document.getElementById('cell_'+i+'_'+j).innerHTML = '';

}

}


}

var on_click = document.getElementById('btn_'+x+'_'+y).getAttribute('onClick');

var on_click_arr = on_click.split("'");

document.getElementById('btn_'+x+'_'+y).setAttribute('onClick',"expand('"+on_click_arr[1]+"','"+on_click_arr[3]+"');");

document.getElementById('btn_'+x+'_'+y).setAttribute('class','btn-icon btn-grey btn-plus');

}

function expand(control,member_number)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {


   // document.getElementById("main_container_heading").innerHTML=xmlhttp.responseText;

   var result = xmlhttp.responseText;

   var result_arr = result.split('|');

   var control_arr = control.split('_');

   document.getElementById('btn_'+control_arr[1]+'_'+control_arr[2]).setAttribute('class','btn-icon btn-grey btn-minus');

   var on_btn_click = document.getElementById('btn_'+control_arr[1]+'_'+control_arr[2]).getAttribute('onClick');

   var on_btn_click_arr = on_btn_click.split("'");

   document.getElementById('btn_'+control_arr[1]+'_'+control_arr[2]).setAttribute('onClick',"contract('"+on_btn_click_arr[1]+"','"+on_btn_click_arr[3]+"');");

   // move everything down

   if ((result_arr.length - 1) > 0) {

   for (j=0; j<3125; j++)
   {

   for (h=0; h<=(5); h++) {

   var here = 3125 - j;

   var num_down = result_arr.length - 1;

   if ((here-num_down) > (parseFloat(control_arr[2]))) {


   var content = document.getElementById('cell_'+h+'_'+(here-num_down)).innerHTML;


//   if (content.indexOf('box_1_5') != -1) {
//
//   alert('here');
//   }

    if (!(content == '')) {

     var click_event = document.getElementById('btn_'+h+'_'+(here-num_down)).getAttribute('onClick');

    var click_event_arr = click_event.split("'");

    document.getElementById('btn_'+h+'_'+(here-num_down)).setAttribute('onClick',click_event_arr[0]+"'cell_"+h+"_"+here+"','"+click_event_arr[3]+"');");


    document.getElementById('box_'+h+'_'+(here-num_down)).setAttribute('id','box_'+h+'_'+here);
    document.getElementById('btn_'+h+'_'+(here-num_down)).setAttribute('id','btn_'+h+'_'+here);



    content = document.getElementById('cell_'+h+'_'+(here-num_down)).innerHTML;

    document.getElementById('cell_'+h+'_'+here).innerHTML = content;

    document.getElementById('cell_'+h+'_'+(here-num_down)).innerHTML = '';

    }



   }

   }

   }

  }

   // end move everything down

   for (i=0; i<(result_arr.length-1); i++)
   {

   var next_right = (parseFloat(control_arr[1]))+1;

   var next_down = (parseFloat(control_arr[2]))+i;

   var result_arr2 = result_arr[i].split('~');

   var formatted_cell = result_arr2[4];

   if (formatted_cell.length < 10) {
   formatted_cell = "27"+formatted_cell;
   }

   var rank = "";

   if (result_arr2[5] == 1) {
   rank = 'bronze';
   } else if (result_arr2[5] == 2) {
   rank = 'silver';
   } else if (result_arr2[5] == 3) {
   rank = 'gold';
   } else if (result_arr2[5] == 4) {
   rank = 'platinum';
   }

   var insert_box = '<div id="box_'+next_right+'_'+next_down+'" class="box round" style="padding-top:0px;padding-bottom:0px;width:200px;background:transparent;display:block;margin-bottom:5px;"><h2 style="height:33px;margin:0px 0px 0 0px;background-image:url(img/rank_'+rank+'.png);"><button id="btn_'+next_right+'_'+next_down+'" onClick="expand(\'cell_'+next_right+'_'+next_down+'\',\''+result_arr2[0]+'\');" class="btn-icon btn-grey btn-plus" style="width: 16px;padding-left: 0px !important;height:13px; background-color: transparent;border-width:0px; border-color: transparent;-webkit-box-shadow:0px 0px 0px;"><span style="left:0px;top:-2px;"></span></button>&nbsp;&nbsp;'+result_arr2[1]+'<div align="right"><span align="right" style="font-weight:normal;align:right;display:block;">Cell: '+formatted_cell+'</br >Com: R'+result_arr2[2]+'&nbsp;&nbsp;People: '+result_arr2[3]+'</span></div></h2></div>';

   document.getElementById('cell_'+next_right+'_'+next_down).innerHTML = insert_box;

   }



    }
  }
xmlhttp.open("GET","business_tree.aspx?is_ajax=1&member_number="+member_number+"&main_member="+document.getElementById('main_member_number').value+'&business_unit='+document.getElementById('business_unit_number').value,true);
xmlhttp.send();
}
</script>


I only added the code to provide more information to the people viewing the question.
Posted
Updated 23-Aug-12 1:27am
v3
Comments
Legor 23-Aug-12 7:17am    
There maybe several reasons for that, but one can't say with this little information about the script or the configuration youre using.

ASP is not ASP.NET, just FYI. You're learning ASP.NET, with VB.NET.

You have to fix your javascript. You should remove all of it, and add one function at a time until you find the one that is breaking. Every browser runs the js in it's own code, so it's not uncommon for something to work in one and not another. The jquery[^] library wraps a lot of those differences and it makes no sense to learn javascript without also learning how to use jquery where-ever possible.
 
Share this answer
 
Comments
Manas Bhardwaj 23-Aug-12 7:25am    
Yup. jQuery makes a lot of sense. +5
Darkness_07 25-Aug-12 11:26am    
theirs some javascript events that ie6 or lower version of ie can't read the script or events.Try the higher version of ie.
Christian Graus 25-Aug-12 11:32am    
I see post posted some code since I looked at this. Is there an error or does it just not work ? Where does it not work ? You can use alert("xxx"); to show messages, and thus work out where your code is going wrong, assuming it's not a flat out error, then the browser will tell you ( look on the bottom left for a message ). Finally, if Darkness_07 is right, perhaps you need to remove some code, unless you're happy for all users to require the higher version he's talking about. If you can tell us which line has the error, we'd be happy to help more, but no-one is going to debug your entire code base.
Quote:
It works fine on all internet browsers accept on IE


Really?

Well, first of all your question conflicts what you are syaing. I think you mean all browsers except IE. Is it?

Second, it's almost close to impossible to have any say without looking at your code.
 
Share this answer
 
Comments
Ruwaldo 23-Aug-12 7:23am    
Yes that is what i meant. And i didnt post any code because when i did that before my questions were down voted for 'code dumping'., but i will improve the question and add the code.
Christian Graus 25-Aug-12 11:29am    
This is clearly just a typo - please don't bust people over basic typos when they don't speak English well
you can use javascript code in separate page.

call it in your aspx page.
 
Share this answer
 
Comments
Ruwaldo 23-Aug-12 7:44am    
so i make an external page with the javascript code in it and the have the aspx page call the function, and this will make it work faster?
jeyamothi 23-Aug-12 7:47am    
yes. because if you use the length javascript in a design it takes loading time is too long
Christian Graus 25-Aug-12 11:30am    
This has nothing to do with his problem though
Ruwaldo 23-Aug-12 8:04am    
I tried this and it still takes too long. Thanks for your input though much appreciated.

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