Please try this code
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function UserDetailsConfirmation() {
return confirm("Are you sure you want to add this ?");
}
function validate() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
var name = document.getElementById('<%=this.txtName.ClientID %>');
if (name.value == "") {
alert("Please Enter Name");
name.focus();
return false;
}
else {
if (UserDetailsConfirmation()) {
confirm_value.value = "Yes";
openwin(name.value)
}
else {
confirm_value.value = "No";
}
}
document.forms[0].appendChild(confirm_value);
}
function UserDetailsConfirmation() {
return confirm("Are you sure you want to add this ?");
}
function openwin(name) {
window.open('Default2.aspx?name=' + name, 'open_window', ' width=640, height=480, left=0, top=0');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server" />
<asp:Button Text="Save" OnClientClick="return validate();" OnClick="Save" runat="server" />
</div>
</form>
</body>
</html>
C#
If you click Ok(in confirm) then new window will be open.
protected void Save(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
//Write code here to save all the controls values
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}