简体   繁体   English

如何通过ASP.NET显示弹出对话框并获取弹出窗口的值

[英]How to show a pop-up dialog through ASP.NET and get the value of the pop up back

So this is what i'm trying to do, i have a web application that deletes a physical file and the file record in the database. 所以这就是我想要做的,我有一个Web应用程序,该应用程序删除物理文件和数据库中的文件记录。 I am trying to find a way to prompt the user to see whether they want to delete the record in the db if the physical file is missing ... 我正在尝试找到一种方法来提示用户,如果缺少物理文件,则是否要删除数据库中的记录...

using ASP.NET, here's where i'm getting stuck ... 使用ASP.NET,这就是我被卡住的地方...

protected void gridViewDeletingRow(...) {
  // get the row to delete
  bool bdelete = deleteFile();

  if(bdelete)
     deleteRecordinDB();
     ScriptManager.RegisterStartupScript(Page, typeof(Page), Guid.NewGuid().ToString(), "javascript:alert('Document deleted successfully!');", true);
  else 
     ScriptManager.RegisterStartupScript(Page, typeof(Page), Guid.NewGuid().ToString(), "javascript:if(!fnConfirmDeleteRecord()){return false};", true);
     // i wanted to able to get the fnConfirmDeleteRecord value back here 
     // so that i can delete the file ... 
     // is there a way to do that?
   }

is there a way to get the value from the popup back? 有没有办法从弹出窗口中获取值?

thanks Daniel 谢谢丹尼尔

Create an Aspx that prompts the user to confirm deletion. 创建一个Aspx,提示用户确认删除。

Open it in a new tab/browser/window by whatever means you choose. 无论您选择哪种方式,都可以在新标签页/浏览器/窗口中打开它。

This article address' your question perfectly : 本文完美地解决了您的问题:

eggheadcafe.com eggheadcafe.com

You could add a javascript confirm to the OnClientClick event of the delete button. 您可以将JavaScript确认添加到删除按钮的OnClientClick事件。 If the column with the delete in it is not already a template column you will have to convert it to one so you have access to the button control markup. 如果其中包含删除的列还不是模板列,则必须将其转换为一个,以便可以访问按钮控件标记。

It might be possible to do this with without converting to a template column, but you would probably have to jump though a few more hoops to find the delete button and insert the code. 可能无需转换为模板列即可完成此操作,但是您可能不得不跳几圈才能找到删除按钮并插入代码。

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you certain you want to delete this item?');"> </asp:LinkButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM