Solved

AJAX Timer Issue

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How we can add Dten600.dll in GAC in c#. 18 50
What!!!??? 5 56
EF5 How do I stop pre-compiled views? 8 45
How does this modal gets closed? 6 36
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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