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

6
  • Have you tried removing class="submit-bt01" and double check again ? Commented May 5, 2012 at 13:07
  • i have already done it..but is of no use.. Commented May 5, 2012 at 13:09
  • 1
    Can you check the view source of this button, how its rendering.Also ensure you have not firing this button event handler from jQuery or page_load method. Commented May 5, 2012 at 13:12
  • i havn't understood it @Deepu can u please explain it Commented May 5, 2012 at 13:14
  • Is it a submit button? Maybe, after you press refresh button your browser performs a page submitting. Open a new tab in the browser and navigate to your site, does click event fire again? Commented May 5, 2012 at 13:14

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

my situation is accurately as in the Scenario A: thanks for Explaining things for me.
at my present situation i cant do Response.Redirect. can any one tell me any other ideas
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
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.

2 Comments

@D Stanley I think you are right(it is a POST ) .can you suggest any solution
It depends on how you want it to behave. Redirecting to a new page is simplest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.