Solved

AJAX Timer Issue

Posted on 2010-11-12
3
480 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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