I have a generic handler which deletes a file from a location after getting a confirmation from the user that is what they really want.
My code is:
public class DeleteFilePDF : IHttpHandler {
public void ProcessRequest (HttpContext context) {
System.Web.HttpRequest request2 = System.Web.HttpContext.Current.Request;
string strSessVar2 = request2.QueryString["fileVar"];
//MessageBox.Show(strSessVar2);
if (File.Exists(strSessVar2))
{
DialogResult dlgRes = MessageBox.Show("Do you really want to delete the file?", "Program Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgRes == DialogResult.Yes)
{
try
{
File.Delete(strSessVar2);
HttpContext.Current.Response.Redirect("PDFAllFilesDisplay.aspx", false);
}
catch (Exception ce)
{
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
My ImageButton
code:
<asp:ImageButton runat="server" ToolTip="Delete File" ID="lnkDelete" OnClick="DeleteFile" CommandArgument='<%# Container.DataItemIndex %>' ImageUrl="~/delete.png" Width="50px" Height="50px" />
My ImageButton
code-behind:
protected void DeleteFile(object sender, EventArgs e)
{
string strFile = GridView1.Rows[Convert.ToInt32(((ImageButton)sender).CommandArgument.ToString())].Cells[0].Text;
string strFolderFile = strDirectory + strFile;
//MessageBox.Show(strFolderFile);
Response.Redirect("DeleteFilePDF.ashx?fileVar=" + strFolderFile);
}
Everything works as it should in debugging environment but outside of that I am not able to use MessageBox.Show()
function. How can I achieve the same thing using a JQuery/JavaScript confirm dialog?