Javascript/C# - 满足语句条件时的确认对话框

Javascript/C# - Confirmation Dialog if statement conditions are met

本文关键字:确认 对话框 条件 语句 满足 Javascript      更新时间:2023-09-26

我正在使用 C# 来替换 SharePoint 库中的文件,我有一个检查文件是否存在的方法,但根据结果,我需要有一个确认对话框供用户警告他们即将覆盖已经存在的文件。

请参阅下面的代码片段:

using (var clientContext = spContext.CreateUserClientContextForSPHost())
       {
           var pageUrl = webUrl + "Pages/home.aspx";
           var list = clientContext.Web.Lists.GetByTitle("Pages");
           if (fileExists(list, pageUrl))
           {
               // show confirmation dialog here
           }
       }

然后,我想根据我的确认对话框的结果有一些逻辑,该逻辑将继续执行代码或只是return;

我一直在看 ClientScriptManager 类,虽然它很接近,但我似乎无法让它完全按照我想要的方式(逻辑相关的确认对话框)。

任何帮助将不胜感激。

你看过这篇文章吗?JavaScript: Alert.Show(message) from ASP.NET Code-Behind

Response.Write("<script>alert('Hello');</script>");

ScriptManager.RegisterStartupScript(this,GetType(),"showalert","alert('Only alert Message');",true)

类似于下面的答案,但要获得确认,请使用符合而不是警报,如下所示:

ScriptManager.RegisterStartupScript(this,GetType(), "confirmation", "confirm('Are you sure you want to overwrite?');", true);