I want to open a confirm window (like confirm() in javascript) when a button clicked, and if it says YES, I want to do some c# code. How can I do this?
EDIT: this is my code.
SCRIPT:
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
THE REST OF MY HTML CODE:
<asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="false" CssClass="Table">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Client ID" />
<asp:BoundField DataField="Name" HeaderText="שם הלקוח" />
<asp:BoundField DataField="PropertyLocation" HeaderText="מיקום הנכס" />
<asp:BoundField DataField="PropertyType" HeaderText="סוג הנכס" />
<asp:BoundField DataField="PropertyArea" HeaderText="שטח הנכס" />
<asp:BoundField DataField="WorkType" HeaderText="סוג העבודה" />
<asp:BoundField DataField="Remarks" HeaderText="שדה חופשי" />
<asp:BoundField DataField="E-mail" HeaderText="מייל" />
<asp:BoundField DataField="Phone" HeaderText="טלפון" />
<asp:BoundField DataField="Password" HeaderText="סיסמא" />
<asp:BoundField DataField="Status" HeaderText="סטטוס" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/Images/ic_delete.png" OnClick="btnDelete_Click" ToolTip="מחיקה" OnClientClick="Confirm()" />
<asp:ImageButton ID="btnTransfer" runat="server" ImageUrl="~/Images/ic_transfer.png" OnClick="btnTransfer_Click" ToolTip="העברה למעקב" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
MY C# CODE FROM BEHIND (WHEN THE DELETE BUTTON CLICKED):
protected void btnDelete_Click(object sender, ImageClickEventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
Response.Redirect("Index.aspx", true);
//connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
//connection = new SqlConnection(connectionString);
//commandString = "SELECT * FROM [Users]";
//command = new SqlCommand(commandString, connection);
}
I am getting this error when I click one of the options in the confirm window:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.