?
Solved

AJAX Timer Issue

Posted on 2010-11-12
3
Medium Priority
?
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 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