Disable gridview refresh after SQL insert? - c#

I'm using a gridview and SQL data source .
After I'm inserting information in data table if I refresh the page the query is executed again and if I refresh it again it will execute again.
Is there any way to disable refresh or make the events unique to be executed only once when the event is raised without execution on refresh
Thanks

if I understand correctly. You have a web form with a button.
You push the button which causes a post back and the event handler for the button press to execute.
Then you hit refresh and the page has the button event handler execute again.
The reason for this is your refreshing the last information sent to the server. Which is the button click information in the __doPostback. This is why you are seeing the event of the button fire again.
ASP.NET doesn't provide a way to do it directly.
Here is an Article talking about how to detect a refresh over a postback.
and your issue is discussed here on other thread

Related

ASP.NET Webforms: Recreate a Postback View on Client-side without calling Event Handler

This is just a curious (potentially stupid) question. I am fairly new to ASP.NET but...
I was testing out some functionality on my ASP.NET Web forms page and every time I test I have to select some options on a few drop-down lists and hit a submit button, at which point the triggers a post-back.
The select some options on a few drop-down lists and hit a submit button action feels mundane and I wanted to know... what changes client-side when you trigger a post-back? and... is there anything I can do in the browser/inspect tool that will return to me the same page view/result of the post-back without select some options on a few drop-down lists and hit a submit button without data maintenance through page life-cycle (Session/ViewState).
I was thinking the only way was to copy the entire HTML on the triggered control event page and have it render that?
An ASP.NET server injects a system JavaScript block with the __doPostBack function. Each postback control on a page calls this function with corresponding parameters. See Doing or Raising Postback using __doPostBack() function from Javascript in Asp.Net for details.
The server generates a full page during a postback and sends it in HTTP response body to the client. As a result, the entire page is refreshed in a browser. If you do not want to send full page postbacks, I suggest you use UpdatePanel:
UpdatePanel Control Overview
Introduction to the UpdatePanel Control

Changing the order of event handling in ASP.NET

I am creating an ASP.NET application which contains an update panel and adds components to it dynamically at runtime. I will have a button which the user clicks to add new fields to the update panel, however, I face a problem in that server controls can only be added to the update panel in Page_Init or Page_Load methods, and page execution will not reach the button click event handler until after these methods have been executed.
Is there any way that the button click event could be handled before Page_Load (but still after the postback data is available)?
Thank you in advance.
I have not understood what you are actually trying to do. The answer is no. The asp.net lifecycle is specific.
Hope I helped!

c# Raise an event in a web page and consume it in another thread

I am not sure if this is possible but here is my scenario:
I have a web page that has a button to save changes. When the user clicks the button, I save the data in the button click event. However I want to raise an Event which that can be consumed in a separate thread.
Is this possible? If so how do I achieve this?
Thanks in advance.

Update the database asynchronously

I have a ListView in ASP.NET where one column consists checkBoxes. I want the user to be able to these CheckBoxes directly in the list (without having to go into edit mode). How I do that, I have received answers in this question
The problem is when the user quickly press several CheckBoxes. It is only the first checkBox that is stored in the database, the other is restored. The user must for every checkBox, wait for the page updated. Is it posible to solve so that the changes are written to the database asynchronously?
You should make Ajax request using JavaScript on checkbox state change
You can use UpdatePanel to write to the database asynchronously and set Trigger to CheckedChanged event

How to prevent firing of last event after page refresh?

Every time I refresh the browser, my button's event handler fires again. How do you prevent this?
One way could be to use an HTTPModule. You can generate a client side GUID, using Javascript, and have that posted back to your server. Then, if the user refreshes, you compare that GUID and see if it already exists on your server. If it does exist, then it's a refresh and you shouldn't perform your button event handler's method. An example of this implementation is described in this blog post.
Another idea could be to redirect the page (or redirect it to itself) after the user has pressed the button. This would give a clean postback and refreshing it shouldn't submit the event again.
I always try to use the PRG (Post-Redirect-Get) pattern, even though it seems a little bit unnatural to the Web Forms system.
This basically means after getting a Button_Click event, you do a redirect, perhaps using QueryString parameters to indicate to the resulting page what to display.
If you are not doing partial page updates with UpdatePanels, you don't 'lose' much doing it that way, anyway. (and if you are using partials, refreshing the page wouldn't necessarily repost anyway!)

Categories

Resources