This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Post-Redirect-Get with ASP.NET
I have a button on my form. Inside the button_click event I insert some data to database. If I click that button and then refresh the page, it seems the button gets clicked again because I find the same data inserted to the database twice. Is there a way to prevent this?
You have to use PRG patern to avoid this problem.
When you refresh the page your last request(either get or Post) resubmitted to the server again.
Solution: In the click event use this at the last
Response.Redirect(#"~\page.aspx");
after insert you can redirect to the same page using Response.Redirect(Request.RawUrl)
this will prevent the problem
Related
This question already has answers here:
Where is ViewState stored?
(5 answers)
Closed 6 years ago.
An ASP.Net website that need to be accessed from C# code, but I don't understand the whole viewstate concept in details.
There is a button that execute such a javascript onclick event javascript:WebForm_DoPostBackWithOptions ...
This makes POST request. One of the fields being posted is viewstate &__VIEWSTATE=
Where it's value comes from, I can't seems to find complete and clear explanation?
The view state is a collection of values where server controls store information that they need. A text box for example stores the previous value in the view state, so that it can check after the postback if the value was changed by the user.
The view state for all controls is encoded and put in a single hidden field in the page. After the postback the view state is decoded so that the (recreated) controls have the same information as when the page was created.
The regular way for the user to make a postback is to press a button (which is an input with type=submit). That will automatically include information about which button was pressed in the data that is posted to the server. The JavaScript that is used to do a postback will simulate this behaviour, i.e. add information about which control was used to make the postback.
This question already has an answer here:
ASP.NET Custom user control to add dynamically
(1 answer)
Closed 7 years ago.
After a page loads a user control, is there a way to remove the user control and replace it with a different one, without doing a browser refresh?
If you do it in an event before ViewState is finalized. Set up both in codebehind, use a placeholder in the page, and swap out the controls accordingly...look up the page lifecycle events - I think you need to do it in an event before Load executes because by then ViewState is established.
Hi
I have one label for question, radiobuttonlist for their answers, next button to move next question & previous button. I am displaying one question per page after clicking next button next question appears, but when i click previous button previous question appears.
But i want previous question with earlier selected answer when i click to previous button.
Asp.net c# Thank you.
Either store and load Question and answer values in the session.
or have one page with a multiview and swich views when navigating between 'pages' this way the viewstate information will be preserved.
You can use asp.net wizard too...
Wizard Class
Wizard Web Server Control Overview
Walkthrough: Advanced Use of the ASP.NET Wizard Control
This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
how to force textchanged to work onblur ??
Actually i want to do tabbing in a Gridview rowwise i have done it.
Problem is that i have done by using onTextChange event now whenever I have to tab away.
I have to text and then enter the tab, then only it works and my requirement is that tab should be done for without entering the text also
So as i'm having all the code i want to forcefully do this onBlur event. ???
You could probably write just a little javascript(using jQuery) so that when the onblur event occurs that the txtChanged event is called on the client side.
Something like
$('#IdHere').blur(function() {
$('#IdHere').change();
});
This question already has answers here:
Best way to detect when a user leaves a web page?
(10 answers)
Closed 3 years ago.
What is the best way to detect if a user leaves a web page without first saving?
I have searched before I posted this question, but I haven't found related topics to deal with ASP.NET (I have controls DropDownList, ListBox, TextBox....)
I would use the JQuery serialize method to save off the form's state in the page's OnLoad event. Then serialize the page again in the OnBeforeUnload event. If the values are different, then the page has changed. You'll have to add a flag to know whether or not the page is unloading because the "Save" button is being clicked. If the values are different and the user didn't click "Save", then display the "Do you want to save before leaving?" box.
One very simple way is to do it the StackOverflow way:
http://www.jonstjohn.com/node/23
Basically it boils down to setting a method to be called in the onbeforeunload javascript event.