Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why in ASP.NET is a button click event executes when page is refreshed?

Tags:

asp.net

In my ASP.Net Web Site I have a button.When I click the button and then reload the page via browser,the click event of the button fires.Where is a problem,please help me.

like image 517
Noro Avatar asked Mar 04 '10 13:03

Noro


People also ask

How do you prevent button click event firing when a page is refreshed?

One way to prevent this from happening is to use Response. Redirect("same_page") to the same page after the event logic. This will force the page to reload and thereafter doing any further page refreshes would not call the button click event.

How do you refresh a page when a button is clicked?

reload() method gives the same result as pressing the reload button on your browser. This method reloads the page from directly the browser's cache by default. If the forceGet property is set to true, the web page will be reloaded from the server.

What happens when a page is refreshed?

For example, if you are on a web page, refreshing the page displays the most recent content published on that page. Essentially, you're asking the site to send your computer the newest version of the page you're viewing. 2. The refresh button, also known as the refresh option, is a function of all Internet browsers.

How can stop page load on button click in asp net?

Set AutoPostback = false for insert button, and this will do the trick for you.


1 Answers

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.

Here is an article talking about how to detect a refresh over a postback.

like image 158
David Basarab Avatar answered Oct 02 '22 18:10

David Basarab