How to use PRG template in asp.net web forms correctly

I have a simple asp.net website with three pages and a problem with the rear browser button that pops up a "... Firefox should send any information that will repeat any action ..." when you click in step 3 .aspx.

Flow: the user lands on step1.aspx, the session begins and user quotes on the product are redirected to step2.aspx. In step 2.aspx, you confirm the purchase by pressing the asp: button. The OnClick event handler, btnPurchase_Click, processes the logic for purchasing and redirecting Response.Redirect ("step3.aspx") to step3.aspx. Step3.aspx just displays a confirmation page (receipt details). The session is destroyed in step 3, and when the user presses the back button of the browser, they are requested with a pop-up message about re-sending. Ideally, I want the user to press the step1 button on impact without re-sending the invitation. Each page is configured to have no cache and redirects to step1 if the session is invalid.

Does anyone have a suggestion for a better stream?

This site will eventually be ported to asp.net mvc / ajax, which is likely to simplify the work of the PRG workflow, but is currently looking for a relatively simple way.

+4
source share
3 answers

A simple solution is to never allow page transfer during postback, but instead accept / store any information that was sent and then redirect to the next page (or itself).

Thus, if the user clicks the back button, he returns to GET, not to POST, and avoids the popup.

+4
source

I ask this question. The stream you mentioned will interfere with the normal functioning of the pages, which of course you already have in mind. Although, I would say that it can be dangerous (against the function that you expect) and is contraindicated. Based on what I see from your question, I will permanently delete pages and pages and save all the logic on one and only page.

I would also be happy to hear what you are trying to avoid with this? Are these dual posts? How to duplicate content in a shopping cart? Partial / incomplete data insertions? With the described method of influencing the rear buttons, you may encounter one problem, but raise another. A wide range of browsers that can act very differently in such conditions.

I see two good options,

UserControl,
Create three UserControls, each of which has the logic of each page. You can programmatically upload them to the page. That is, the on bnButton_Click Event. User controls are loaded using LoadControl("PathToAscxFileOnDisk.ascx") .

Panel
I would also think of three <asp:PlaceHolder></asp:PlaceHolder> or perhaps better <asp:Panel></asp:Panel> to include all the logic.

In this case, you are completely free of feedback problems and can focus on moving your functions to business logic and use Code-File to control the flow in show / hide and populate controls in / from panels / UserControl controls. Perhaps you can also control the feedback URL / click and the enter / enter key.

And you mentioned Ajax,
Ajax is absolutely ready to make your page standstill (which means that you can work without cache, sessions, viewstate, etc. Although the problem is that users can move between pages. I think that even Ajax has less help in while you save a three-page solution.

I would say that a simple task is to move the aspx files to each ascx and create aspx as a master container. With this option, you even avoid duplicate names (for example, if you copy / paste code in the panel) and problems with the stream / logic of Page_Load.

+2
source

If I understand correctly, you are not using PRG yet.

In step 2, temporarily save the information and redirect it. How you do this, a lot depends on your application: session, database, cookies, etc. - all options with different characteristics.

Then redirect to show this information.

The same thing happens in step 3.

If you return in step 3, you will go to step 2. But if you return to the GET request, there will be no warning. As you said, your application destroys the session data by 3, so in accordance with what you said, the user will go to step 3.

Perhaps I missed something because of what you said.

+2
source

All Articles