I have use jquery dialog popup for showing message in popup and Ihave passed message from code behind.Now I want yes or no confirmation in popup and if user clicks yes then only proceed to delete. But I dont have any idea that how to perform from code behind.
<script type="text/javascript">
function ShowPopup(message) {
$(function () {
$("#dialog").html(message);
$("#dialog").dialog({
title: "jQuery Dialog Popup",
buttons: {
text: "Yes",
click: function () {
$(this).dialog('close');
}
},
text: "No",
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
});
};
</script>
<div id="dialog" style="display: none">
</div>
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string message = "Are you sure you want to delete";
Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
DataTable dt = GridView1.DataSource as DataTable;
sQLcONN.Open();
MySqlCommand objcmd = new MySqlCommand("delete from shoppingcart where with_puja = '" + Convert.ToInt32(dt.Rows[e.RowIndex]["id"]).ToString() + "'", sQLcONN);
objcmd.ExecuteNonQuery();
Bindgrid();
sQLcONN.Close();
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
Set the confirmation value in a hidden field from the js
ASP CODE:
<asp:HiddenField id="ConfirmBit" runat="server" />
JAVASCRIPT CODE:
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").hide();
function ShowPopup(message) {
$("#dialog").html(message);
$("#dialog").show();
$("#dialog").dialog({
title: "jQuery Dialog Popup",
buttons: {
"Yes": function () {
$('#ConfirmBit').val("YES");
$(this).dialog('close');
},
"No": function () {
$('#ConfirmBit').val("NO");
$(this).dialog('close');
}
},
modal: true
});
}
});
Now Compare the Comparison bit in the code behind and based on that perform the further operation.
CODE BEHIND:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string message = "Are you sure you want to delete";
Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
string cBit= ConfirmBit.Value;
if(cBit.Equals("YES"))
{
DataTable dt = GridView1.DataSource as DataTable;
sQLcONN.Open();
MySqlCommand objcmd = new MySqlCommand("delete from shoppingcart where with_puja = '" + Convert.ToInt32(dt.Rows[e.RowIndex]["id"]).ToString() + "'", sQLcONN);
objcmd.ExecuteNonQuery();
Bindgrid();
sQLcONN.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
Happy Coding :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.