Solved

AJAX Timer Issue

Posted on 2010-11-12
3
456 Views
Last Modified: 2012-05-10
I have an ASP.NET application that uses ajax, update panel, and a timer.  The page should load fully so that the user see's the please wait text/images.  Then a timer should execute a function one time.  Below is my code.  The issue is that I have a function called LoadQuestions.  It can take up to 15 seconds to update data through web services to a seperate application.  If I comment out loadquestions, the timer ticks, then the code executes fine.  If I leave loadquestions in the code, it seems to time out the ajax.  The remaining code executes, but then the page dies and the redirect doesnt complete.  Any ideas?

        //----------------------------------------------------------------------------------
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.MaintainScrollPositionOnPostBack = true;
            ScriptManager.RegisterStartupScript(this, typeof(Page), "ScriptDoFocus", Utility.SCRIPT_DOFOCUS.Replace("REQUEST_LASTFOCUS", Request["__LASTFOCUS"]), true);

            if (!IsPostBack)
            {
                if (Session["KEY"] != null)
                {
                    Session["REDIRECT"] = null;
                    Timer1.Enabled = true;
                    Session["Timer"] = null;
                    Constit constit = (Constit)Session["KEY"];
                    constit.ProcessingError = null;
                    Session["KEY"] = constit;
                }
            }
            else
            {
                if(Session["Timer"] != null)
                    Timer1.Enabled = false;
            }

        }
        //----------------------------------------------------------------------------------
        private void ProcessOrder()
        {
            Utility utility = new Utility();
            PaymentProcessor payment = new PaymentProcessor();
            Constit constit = (Constit)Session["KEY"];
            string message = string.Empty;

            decimal price = constit.ExamPrice;
            if (constit.Reinstate)
                price = price + 200;

            int scTransNum;
            if (!payment.ProcessMeetingPurchase(constit.Constit_ID, constit.BillFirstName, constit.BillLastName, constit.MeetingUID, constit.Reinstate, price, "COMP", constit.CCNumber.Replace("-", ""), constit.CCExpDate, constit.SecurityCode, constit.BillStreet, constit.BillZipCode, constit.HomePhone, constit.EmailAddress, constit.ExamName, out scTransNum, out message))
            {
                constit.ProcessingError = "<b>Can Not Process Application</b><BR/> <Font Size=-1>" + message.Replace("meeting", "exam");
                Session["KEY"] = constit;
                string redirectURL = Page.ResolveClientUrl("process_payment.aspx");
                string script = "window.location = '" + redirectURL + "';";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", script, true);
            }
            else
            {
                utility.SendReceipt(constit.ExamPrice.ToString("C"), constit.Exam + " Exam", constit.EmailAddress, constit.CCNumber.Replace("-", "").Substring(constit.CCNumber.Replace("-", "").Length - 4, 4), constit.FirstName + " " + constit.LastName, constit.Constit_ID);
                LoadQuestions(constit, scTransNum);
                string redirectURL = Page.ResolveClientUrl("application_complete.aspx");
                string script = "window.location = '" + redirectURL + "';";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", script, true);
            } 
        }
        //----------------------------------------------------------------------------------
        private bool LoadQuestions(Constit constit, int scTransNum)
        {
            string error = string.Empty;
            if (constit.LoadQuestions(constit, scTransNum, out error))
            {
                return true;
            }
            else
                return false;
        }
        //-----------------------------------------------------------------------------
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Session["Timer"] = true;
            ProcessOrder();
        }
        //-----------------------------------------------------------------------------

Open in new window

0
Comment
Question by:Rowdyone52
  • 2
3 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34128279
You can try and play with the AsyncPostBackTimeout  property of the ScriptManager.

<asp:ScriptManager ID="ScriptManager" runat="server" AsyncPostBackTimeout="120"></asp:ScriptManager>

The value is in seconds, so the above line would mean 2 minutes.

Try setting a reasonable value there and see if it helps you.
0
 

Accepted Solution

by:
Rowdyone52 earned 0 total points
ID: 34167593
I tried adjusting the AsycPostBackTimeout and it still had issues.  

I ended up using the RegisterAsyncTask method to call the function.  
0
 

Author Closing Comment

by:Rowdyone52
ID: 34195050
Found my own solution
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now