I have an asp.net button in my page, after I click the button, it is clicked again and again whenever I refresh the same page.
I tried;
if (!IsPostBack)
{
.....
}
for the click function of the button, but in this case button is not working.
<asp:Button ID="btnCommentSubmit" runat="server" Text="Submit" CssClass="leaveAComment" onclick="btnCommentSubmit_Click" />
above is the button.
protected void btnCommentSubmit_Click(object sender, EventArgs e)
{
string cityID = BusinessClass.Default.findCityIDByCountryAndCityName(Request.QueryString["city"].ToString(), "url").ToString();
BusinessClass.Default.makeComment(txtComment.Text, Session["userID"].ToString(), cityID);
txtComment.Text = null;
}
and this is the function.
If don’t get you wrong your problem is when you hit F5 after clicking the button. Trying to resubmit the form is the normal behavior and is not related to asp.net but to browsers in general.
F5 causes to re-execute last request to the server, in your case, a POST request.
A way to avoid this issue is implementing the web pattern Post/Redirect/Get