Solved

How to deal with 'Page_PreRender(object sender, EventArgs e)'  when iterations (loops) are involved.  Getting double the transactions

Posted on 2008-10-23
4
701 Views
Last Modified: 2013-12-17
Greetings:

I have a web page that generates help desk tickets.  Certain request should generate four tickets for the user's one request  -  so that four different departments of the company can take action.

With my current setup things worked fine when there wasn't a FOR LOOP involved that iterates four times:

 for (i = 0; i < 4; i = i + 1)

Is it possible the Page_PreRender() causes duplicates?  I don't get this problem when a step through the debugger but it does surface after I put the code on the production server.

Any ideas?

Thanks!
0
Comment
Question by:John500
  • 2
4 Comments
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22795758
firstly, you dont need to do
i=i+1 in your loop. just do i++ though that shuoldnt make much difference.

Post more code please so we can have a look.

Fyi : Page_Prerender fires only once.
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 250 total points
ID: 22806180
as per msdn the prerender will be called for every control
http://msdn.microsoft.com/en-us/library/ms178472.aspx

i will recommend you to move your logic to the page_load event
that will be the best place as the load is called only once and you can take actions there safely
0
 
LVL 6

Assisted Solution

by:AmarIs26
AmarIs26 earned 250 total points
ID: 22806594
Every event in the lifecycle is called only once. Page_Prerender event gets called first then it calls the pre_render event of every control. If your logic is in prerender event of the page then its fine but like i said the issue might lie somewhere else. Forexample, if your page just finished creating tickets due to a postback and the user presses the refresh button of the browser or hits F5 then it will do another postback which can result in same processing to occur resulting in 4 more tickets.
 
0
 

Author Closing Comment

by:John500
ID: 31509419
Thanks.  Although this was not the actual problem, the information you both provided helps in other areas.  The problem boiled down to having this method in the loop:  

public void Confirmation(bool good, string text, string url);

It needed to be outside of it.  Thanks again.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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