'Response.redirect execute the code inside the pageload twice

I have this link http://localhost:54818/offerslinks/offers.aspx?ID=1 when i clicked it. it loads the page and executes this code twice

enter image description here

this code execute twice can any one help me with that ?



Solution 1:[1]

You might have to share how webform1 is calling the web page that you response.redirect to (maybe the same page???).

You have a isPostBack check, and note that page load ALWAYS will trigger again, and each time for each button click (post-back) on that given page. So, if you have a simple button on that that webform1, click on it, the page-load event will fire again, and THEN your button code stub will then run.

Of course with a is-postback = false test, then ONLY on first page load should that code run runside that if !PostBack.

However, the code WILL run again if your response.redirect points to the same page. If you have in that same page, a response.redirect to the SAME page, then not only will page load trigger again, so will the code inside of !IsPostBack code stub.

So, we need more details, or more markup to be posted here (and post the markup in place of screen shots - screen shots are a pain to read, but WORSE is I will often cut + paste markup into a test page while answering questions here - I can't do that if you post image(s), since then I would have to take away time from my life and family, and re-type such markup (or code) to test such things for you when answering questions here.

My best guess is that the response-redirect points to the same page. Thus upon that code running, it re-directs to the same page, and that would thus cause the page load to run again, and also cause isPostBack to be false, which then means the code isside that stub will also run again.

So, missing from this information is how/when/where that page is being loaded - without those details, we are in effect throwing darts in a room with the lights out.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Albert D. Kallal