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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
It’s because clicking that button sends a POST request to your page. The POST data is kept in the http headers and when you refresh, it’s sent again to server.
Your browser should warn you when you try to refresh the page.
Method 3
This is by design. When you click a server side button (with the runat="server" attribute), a click will cause a postback and the button click event will fire.
If you want some client side behaviour, you need to use the OnClientClick attribute, as described in this MSDN article (How to: Respond to Button Web Server Control Events in Client Script).
Method 4
If this is really important for someone, then they can refresh the page again through a Response.Redirect(). This is the easiest solution that I have been able to find.
Method 5
the easiest way to solve this issue is to redirect your page to some url or refresh your current page using Response.Redirect(Request.RawUrl);
Method 6
I had the same issue and it was solved by putting the button as asp:AsyncPostBackTrigger of the updatePanel.
Method 7
If you want to refresh Part of your page then put the control inside the UpdatePanel if the 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>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0