0

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..

None
  • 5,582
  • 21
  • 85
  • 170

2 Answers2

3

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? E.g. 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.

Community
  • 1
  • 1
C.List
  • 657
  • 8
  • 16
  • my situation is accurately as in the Scenario A: thanks for Explaining things for me. – None May 05 '12 at 13:31
  • at my present situation i cant do Response.Redirect. can any one tell me any other ideas – None May 05 '12 at 13:36
  • Can't you do this in your page:? protected override void button_onclick(object sender, EventArgs e) { SendMail(); Response.Redirect(Request.Url.AbsoluteUri); } ...note that the important thing is that you are not redirecting to a new page, you are redirecting to the page you are already on, but the redirect will do a GET and not a POST – C.List May 05 '12 at 15:44
1

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.

D Stanley
  • 149,601
  • 11
  • 178
  • 240