I am having a asp.net button control and a javascript confirmation box which is executed on that button click. If the javascript returns true than only perform click event of button..
HTML:
<asp:TextBox ID="txtSubject" runat="server" CssClass="textbox" Width="454px" CausesValidation="true" onfocus="ddlSelect()"></asp:TextBox>
<asp:Button ID="btnSaveSend" CssClass="myButton" runat="server" Text="Save & Send"
OnClientClick="javascript:return SubjectEmpty()" OnClick="btnSaveSend_Click" />
Javascript:
function SubjectEmpty() {
var subject = document.getElementById("<%=txtSubject.ClientID%>").value;
var result = confirm("Are you sure you want to send mail:" + subject + " ? We shell check for the availability..");
if (result == true) {
return true;
}
else {
return false;
}
Code Behind:
protected void btnSaveSend_Click(object sender, EventArgs e)
{
//Do something
}
The problem is even if I select cancel it executes btnSaveSend_click()
return confirm('Are you serious?');
But you say the page gets posted to the server and the event executes...so why do you think that is so? – deostrollOnClientClick="javascript:return false;"
should not trigger a postback. You need to debug and find out whyconfirm(...)
is actually returningtrue
in your case... – deostroll