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
694 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.

831 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