Hi comunidadmexi...,
Refer below code.
HTML
<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);
}
function jsShowHideProgress2() {
setTimeout(function () {
document.getElementById('imgloadinggif2').style.display = 'block';
}, 2000);
deleteCookie();
var timeInterval = 2000;
var loop = setInterval(function () {
if (IsCookieValid()) {
document.getElementById('imgloadinggif2').style.display = 'none';
clearInterval(loop)
}
}, timeInterval);
}
function deleteCookie() {
var cook = getCookie('ExcelDownloadFlag');
if (cook != "") {
document.cookie = "ExcelDownloadFlag=; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
}
function IsCookieValid() {
var cook = getCookie('ExcelDownloadFlag');
return cook != '';
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
</script>
<div class="container">
<asp:ImageButton runat="server" ID="imgxls" Visible="true" OnClientClick="jsShowHideProgress2();Confirm();"
OnClick="imgxls_Click" ToolTip="Download" ImageUrl="https://i.imgur.com/73e8Dja.png" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<img style="display: none; margin-left: auto; margin-right: auto;"
id="imgloadinggif2" src="/aspnet/img/ajax-loader.gif" alt="loading.." />
</div>
Code
C#
public void imgxls_Click(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
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);
}
}
VB.Net
Public Sub imgxls_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim confirmValue As String = Request.Form("confirm_value")
If confirmValue = "Yes" Then
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('You clicked YES!')", True)
Else
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('You clicked NO!')", True)
End If
End Sub
Screenshot