简体   繁体   中英

button click event automatically fires

My situation is like this i have a asp button inside my user control

  <asp:Button ID="btnSubmit"
        Text="Send Notification" class="submit-btn01"   onclick="btnSubmit_Click1" runat="server" />

in my browser when I refresh my page, button click event automatically happens.i cant figure out what is wrong with this..

Your question is a little vague. It sounds like you have one of the following scenarios:

Scenario A:

  1. Load the page by URL
  2. Click submit, a refreshed page comes back.
  3. Hit F5 on the page and you get a message asking if you want to resubmit the form, and the Submit button action happens again

Scenario B:

  1. Load the page by URL
  2. Hit F5 on the page and and the Submit button action happens

For Scenario A;

if you want to avoid the re-postback, you should do a Response.Redirect() to the current page in the btnSubmit_Click1 event handler, as mentioned in more detail here: asp.net prevent form submission twice

For Scenario B;

  1. Are you doing any javascript in the page that would cause it to behave differently on each page load?
  2. Are you getting to the page by way of a post-back from a different page?
  3. Are you doing anything odd/fancy in the page life-cycle on the code-behind side? Eg CreateChildControls?

...if it's scenario B, and the answer to these are no, then I'm very curious to see what the final cause of the problem is as I can't imagine why a page would behave differently between a load and a reload.

Refresh is likely repeating the last action that was performed if it was a POST.
Since the last action was to submit the form using your button that is getting replayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM