Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a project in which I have added all java script and jQuery references. I have opened a popup. this popup have multiple links. By clicking on link we are getting values directly from controller action method by hitting it using Ajax call. And display html below the link like accordion. But some time (usually when I click on link after 3 or 4 minutes.) Ajax call takes too much time to populate values from controller. When I put debugger on action method from which it should get data. It is not hitting that action quickly. Ajax call starts but hit action method about 60 sec later or more. What could be the reason behind it? Below is my code.

Method to call.

C#
public string SavedReportHtml(string SessionID)
{
            DataView dvFileInfo = dtFileInfo.DefaultView;
            dvFileInfo.Sort = "CreationTime desc";
            returnHtml.Append("<table id='tblSavedReport' class='table table-condensed table-striped table-bordered' style='text-align:center; valign:middle;'><tbody>");
            returnHtml.Append("<tr><td style='width:10%;'><b>Select File</b></td><td style='width:20%;'><b>File Name</b></td>");
            returnHtml.Append("<td style='width:40%;'><b>Description</b></td><td style='width:20%;'><b>Date Created</b></td>");
            returnHtml.Append("<td style='width:10%;'><b>Delete File</b></td></tr>");
            for (int rCount = 0; rCount < dvFileInfo.Count; rCount++)
            {
              string url_content = Url.Content("~") + "/UserIDs/" + m_userID + "/" + dvFileInfo[rCount]["Name"].ToString();
              returnHtml.Append("<tr><td><input type='image' src='../../../Images/PdfImg.jpg' id='" + "" + "' class='imgrounded' width='20px' value='" + url_content + "'/></td>");//SelectFile
              returnHtml.Append("<td>" + dvFileInfo[rCount]["Name"].ToString() + "</td>");//FileName
              returnHtml.Append("<td>" + dvFileInfo[rCount]["FileDesc"].ToString() + "</td>");//Description
              returnHtml.Append("<td>" + string.Format("{0:MMM dd, yyyy}", Convert.ToDateTime(dvFileInfo[rCount]["CreationTime"].ToString())) + "</td>");//DateCreated
              returnHtml.Append("<td><button class='btn btn-default' value='" + dvFileInfo[rCount]["Path"].ToString() + "'><i class='icon-remove-sign'></i>&nbsp;Delete</button></td></tr>");//DeleteFile
            }
            returnHtml.Append("</tbody></table>");

return returnHtml.ToString();
}

Ajax call to call Action method.

SessionID is stored in Hidden field.


JavaScript
$("#btnSavedReports").click(function () {
      $("#PopupTitle").html('@Model.FullName');
      $('#modelSavedReports').modal('show');
      return false;
    });
    $('#modelSavedReports').on('show.bs.modal', function () {
      $("#divSavedReportDisplay").html("");
      var options = { type: "POST",
        url: '@Url.Action("SavedReportHtml", "WorksiteMarketing", new { area = "VitalLTC" })',
        cache: false,
        data: { SessionID: SessionID },
        success: function (data) {
          $("#divSavedReportDisplay").html(data);
          $('#modelSavedReports').appendTo('body');
          $("#tblSavedReport td").click(function () {
            if ($(this).index() == 0) {
              var fileLocation = $(this).children().attr('value');
              myWindow = window.open(fileLocation, 'Wkmt', "width=800,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=no");
              try {
                myWindow.focus();
              }
              catch (e) {
                myWindow.close();
                myWindow = window.open(fileLocation, 'Wkmt', "width=800,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=no");
              }
            }
            else if ($(this).index() == 4) {
              var $tr = $(this).closest('tr');
              var myRow = $tr.index();
              if (myRow != 0) {
                $tr.remove();
                var fileLocation = $(this).children().attr('value');
                $.ajax({ data: { FileLocation: fileLocation }, cache: false, url: '@Url.Action("DeleteWkmtReport", "WorksiteMarketing")' });
              }
            }
            else {
              return false;
            }
          });
        }
      };
      $.ajax(options);
    });
Posted
Updated 27-Feb-15 0:59am
v3
Comments
Simon_Whale 27-Feb-15 4:51am    
debug your application, how long does it take to get the data from the database? how many rows are in your DataView?
ShivKrSingh 27-Feb-15 5:00am    
actually takes time between button click to reach to methods after reaching to method its hardly takes 2 seconds. Only 5 rows are there in dataview with 6 columns

1 solution

You said this happens if you leave the site idle for 3 or 4 minutes? This is probably because the web server unloaded your process because there was nothing happening. When you make another request, by clicking on a link, the web server has to reload the process and recompile code. This can take quite a bit of time depending on your site and code.

This behavior is by design in IIS.

Also, running the site in the debugger slows everything down quite a bit.
 
Share this answer
 
Comments
ShivKrSingh 2-Mar-15 1:28am    
thanks for reply. but when i have tested same scenario with demo project it is working fine. even if i click on link after 5 or 30 min.

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