Solved

AJAX Timer Issue

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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