[ACCEPTED]-Why in ASP.NET is a button click event executes when page is refreshed?-asp.net
If I understand correctly.
You have a web 11 form with a button.
You push the button which 10 causes a post back and the event handler 9 for the button press to execute.
Then you 8 hit refresh and the page has the button 7 event handler execute again.
The reason for 6 this is your refreshing the last information 5 sent to the server. Which is the button 4 click information in the __doPostback. This 3 is why you are seeing the event of the button 2 fire again.
Here is an article talking about how 1 to detect a refresh over a postback.
It's because clicking that button sends 5 a POST request to your page. The POST data 4 is kept in the http headers and when you 3 refresh, it's sent again to server.
Your 2 browser should warn you when you try to 1 refresh the page.
This is by design. When you click a server 7 side button (with the runat="server"
attribute), a click 6 will cause a postback and the button click 5 event will fire.
If you want some client 4 side behaviour, you need to use the OnClientClick
attribute, as 3 described in this MSDN article (How to: Respond 2 to Button Web Server Control Events in Client 1 Script).
If this is really important for someone, then 3 they can refresh the page again through 2 a Response.Redirect(). This is the easiest 1 solution that I have been able to find.
the easiest way to solve this issue is to 2 redirect your page to some url or refresh 1 your current page using Response.Redirect(Request.RawUrl);
I had the same issue and it was solved by 2 putting the button as asp:AsyncPostBackTrigger 1 of the updatePanel.
If you want to refresh Part of your page 2 then put the control inside the UpdatePanel
if the 1 control causes PostBack
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button CssClass="btn btn-default"
onClick="uploadAttachmentToList" runat="server"
ID="btnUpload" ClientIDMode="Static" Text="Upload"
/>
</ContentTemplate>
</asp:UpdatePanel>
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.