问题描述
我有一个通用的处理程序而获得来自用户的确认是他们真正想要的东西后删除从位置的文件。
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.
我的code是:
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;
}
}
}
我的的ImageButton
code:
<asp:ImageButton runat="server" ToolTip="Delete File" ID="lnkDelete" OnClick="DeleteFile" CommandArgument='<%# Container.DataItemIndex %>' ImageUrl="~/delete.png" Width="50px" Height="50px" />
我的的ImageButton
code-背后:
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);
}
一切正常,因为它应该在调试环境,但是那之外,我不能够使用 MessageBox.Show()
功能。如何能够做到用一个jQuery / JavaScript的确认对话框是一回事吗?
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?
推荐答案
从JavaScript和流程服务器点击获取确认
Get the confirmation from javascript and process server click
<asp:ImageButton runat="server" OnClientClick="return getConfirmation()"
ToolTip="Delete File" ID="lnkDelete" OnClick="DeleteFile"
CommandArgument='<%# Container.DataItemIndex %>'
ImageUrl="~/delete.png" Width="50px" Height="50px" />
然后JS code
Then JS code
function getConfirmation(){
return window.confirm("Do you really want to delete the file?");
}
有可用于显示一个确认框一些不错的用户界面。看看jQuery的模态对话框或引导bootbox等
There are some nice UIs available for showing a confirmation box. Check out jQuery Modal dialog or bootstrap bootbox, etc
这篇关于如何从C#显示确认对话框客户端和使用结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!