My question is - what is the difference between page refresh (if I press f5) and postback (If I press a button)?
Can anyone please tell me?
Thanks in advance.
A refresh mean a complete reload of the page, without any form data. This is essentially an HTTP GET.
A post back is when the page is posted to itself (through the form action=""). This is essentially an HTTP POST.
Lets have the actual difference between refresh and explicitily submitting a page :
1) Refresh does not mean to post back the page with get method..(You can check it with response.write request.form("some input type")).
2)Difference lies with the data sent to the server :
in case of explicit submit form is submitted with latest value(i.e it recognize the changes in form elements)
But in case of refresh, form is submitted with default form value.(i.e if you change the value of form element it will not reflect at server.)
when page is refresh that means page is sending request to server without any data that means HTTP GET but in another case suppose a event is fired that causes postback after
page completely load on browser if we press f5 or do refresh then it will send privious data with request instance, that means again for that data server will perform operation...
have u seen somtimes while you are doing online sopping after selecting item and press accepet button uyou get total price ,now again if you refresh then for that selected item it will again go to server that means you are buying same things twice.....i think now you get everything what i want to say...
in when page is postback then code of that page again compile and also processing `request data`. this process will going on
Related
There is some generated contents with the links on an ASP.NET page, which is created after the user inputs values and hits a button. The links take the user to another page.
When the user hits the Back button, the generated content is gone as the page returns to its initial state with the inputs cleared and generated content not there.
Is it possible to preserve the state of the page after its content has been generated and restore it after the Back button was clicked?
I think you can you can you temporary cookies.
and on load check whether cookie is exists or not.
Save the inputs in the session, so that the page will know how to correctly render on later requests. Even better, have the first code that runs when the data is submitted redirect to new page with a URL parameter that you use to know which links to show. This is a called a POST-REDIRECT-GET pattern.
I was given a task to solve a bug on some old project that someone else wrote.
The project is ASP.Net deployed on IIS.
Scenario:
Open Request form.
Fill personal details.
Click button "Add Items" to open items selection window.
Select items and close the item selection windows.
Expected:
Back in Request form, it is now showing both the personal details, entered in
step 2 and now, on the same request page, the list of selected items, selected in step 4.
Actual:
Back in request form, not showing personal details and only showing
the selected items.
From the code I learn that every field on the request form is:
Saved to the session (E.g onChange in JavaScript call code-behind save
function)
Load from the session on Page_Load
I guess the above is needed as a replacment machanism for the ViewState,
because in the above scenario it is required for the form fields (E.g personal
details) to persist across several pages. (The opening of other windows
to add items...)
Also from the code I learn that items added on "Add Items" windows are:
Saved to the session in the page "Add Items"
Loaded from the session in the Page_Load of page "Request"
Now instead of working on the project over at the customer's offices we copied
the project and deployed it back in our offices - only problem is now it is
working fine - that is, both the personal details and the list of selected
items are showing as expected.
I would like any suggestions... What could be the cause of such
behavior?
Also in case I will not be able to recreate the problem on my environment,
what should I check/debug on the customer's office?
...What could be the cause of such behavior?
Based on your symptoms, it sounds like could be happening is the server is relying on a client-side script (to set the form values sent down from the server's response) that has a dependency (e.g. jQuery) that might not be supported by the (possibly outdated) browser being used.
...what should I check/debug on the customer's office?
Here is what I gather is supposed to be happening after the client has the form open:
User enters values in form control(s). ("Personal Details")
Client-side event handler sends asychronous requests to the server (no callback) in order to save form values to the user's Session.
User clicks a button. ("Add Items")
Client-side event handler opens a new window that sends a request to the server for the "Items Selection" page.
Response is received from the server and the "Items Selection" page is displayed on the client.
User selects values for controls. ("Items Selection")
User clicks a button ("Close Window")
Client-side event handler:
Sends a request (with the "Items Selection" values) on behalf of the previous window to the server for the "Personal Details" page.
Closes the current window.
Previous window receives response, page reloads completely, and all form data is still present (reloaded).
We know at the very least 9. isn't actually happening properly, since this is your stated problem.
Assuming I have your implementation correct, you should start by determining how the values are supposed to be written to the controls during the last step (e.g. server controls' values assigned directly or server registers start-up client-script to write the form values). Then you should check the values that are sent to the method you discovered. If the values are incorrect, keep backing up to each previous server request to see what is the resulting Session state before the response. If the values are correct then you know something is going wrong (most-likely client-side) after the client receives the response from the server (I think this should only happen if my jQuery theory above is correct).
Move backward through history skipping the same page with different query string
The above is similar to my question, but I'll be more specific as mine concerns POSTs:
Scenario:
User is on Product Listing page. (Shorts.aspx)
User picks a product and navigates to product detail page (Best-Cargo-Shorts.aspx)
User clicks add to cart which performs postback (POST) of form to same page. (Best-Cargo-Shorts.aspx) -- this now shows Details page again, but with an Added TO Cart message at the top.
Current Behavior:
After the Add TO Cart form post; when the user clicks the Back button they navigate back to the "pre-post" version of the same page.
Desire:
When a user clicks the BACK button, I'd like it to go to Shorts.aspx, NOT Best-Cargo-Shorts.aspx, effectively Skipping the "pre-POST" page, or more accurately NOT STORING the 2nd POSTed page (Best-Cargo-Shorts.aspx).
Furthermore, I always want to avoid that "Page Content Expired" message. I just never want the POSTed version of the page in history. In this way, the following could also be true.
Shorts.aspx > Best-Cargo-Shorts.aspx > Best-Cargo-Shorts.aspx [POST] > Cart.aspx
If on cart and BACK button is pressed, I want the browser to navigate to Best-Cargo-Shorts.aspx (without the POST).
Is this possible with C#? Furthermore, is there a non-javascript solution?
Thanks.
One common way of handling this is the Post-Redirect-Get pattern.
In essence, the target of a POST request always responds with a 303 See Other (if HTTP 1.1) or 302 Moved Temporarily (if HTTP 1.0) status code redirecting the request as a GET, and usually eliminating the expired POST page from history. Potential downsides include the form parameters possibly remaining attached to the GET as a query string, and I've no clue how well it would (or wouldn't) integrate with ASP.Net Forms, MVC, or other web frameworks.
Generally, you should be using the post-redirect-get pattern, i.e. after the user adds the item to the card using POST, redirect him to Best-Cargo-Shorts.aspx with 302.
Now to your question, I would use Ajax for the post. I cannot think of a cross-browser way to achieve the desired behaviour using only server side code.
I have a set of interlinked dynamic web pages.
When the user clicks from one page to another, I don't want any caching to happen - the request must go to the server, which will return an up-to-date page.
But when user clicks Back, I do want the cache to be used - some of the pages can take some time to generate, which is fine when you're clicking through to them, but not when you're clicking Back.
Is this possible?
(Please don't suggest re-engineering everything as a single page making AJAX queries!)
(Note: this question is the opposite of the ever-popular "How do I prevent caching when the user clicks Back?" question.)
A common trick for avoiding the browser cache when dealing with dynamic pages is to add a parameter to the link url that is unique (using the time, to the millisecond is common).
When the user hits the 'back' button, they will go back to the last rendered version, and should get it from the cache.
I have a simple form that dynamically presents a data entry form, and the user does a postback and the results are saved to a database. I have created a new version of the form, and based on some information on a database, when the user requests the URL of the old form, I wanted to do a Server.Transfer to the new *.aspx page to generate the page and handle the postback. Since the URL of the page will not change, does that mean the postback gets sent to the original page? Would I then need to check if it's a postback, and if so then call Server.Transfer and allow the form data to be transfered to the new page?
It depends on what you mean by "gets" the postback. The first page will get the form values posted of course, since they are sent from the client. However, how far the first page gets through reacting to the postback information depends on when in the lifecycle you initiate the Server.Transfer. If it is extremely late in the lifecycle (like a click handler), then the first page will have pretty much gone through the entire postback process.
The optional parameter to preserve form values in Server.Transfer dictates whether the second page also reacts to the request as if it is a postback.
Take a look at the HTML source of the page after the Server.Transfer. If the form's action is the new ASPX then you are okay.
It would probably be easier to use a regular redirect. That way you don't have these kinds of issues.