在网站的 C# 后端代码中,我有以下代码为用户显示一条消息,列举他们将要提交的数据,并要求人工确认信息是否准确。
这是在 C# 中执行的,而不是在 JavaScript 中执行的,所以我如何访问 confirm
函数的结果?
如果他们单击“确定”,我的 C# 逻辑需要遵循不同的路径,而如果他们单击“取消”。
我正在开发一个非常古老的应用程序(13 年),它已经有一段时间没有受到影响了。
因此,我无法更改应用程序的总体设计。
ClientScript.RegisterStartupScript(this.GetType(), "InvalidEntrySubTypeAlert", "confirm('" +
"Are you sure you want to create the following deal?\n" +
"\nDeal ID :\t\t\t" + nDealID +
"\nCompany Name :\t\t" + txtCompanyName.Text +
"\nEntry Subject :\t\t" + txtEntrySubject.Text +
"\nBusiness Lead :\t\t" + ddlBusinessLead.SelectedItem.Text +
"\nLicense Status :\t\t" + ddlLicenseStatus.SelectedItem.Text +
"\nEffective Date :\t\t" + string.Format("{0:MM/dd/yyyy}", calEffectiveDate.SelectedDate) +
"\nExpiration Date :\t\t" + string.Format("{0:MM/dd/yyyy}", calExpirationDate.SelectedDate) +
"\nLicense Location :\t\t" + txtLicenseLocation.Text +
"\nEntry Sub Type :\t\t" + ddlEntrySubType.SelectedItem.Text.Split(' ')[0]
+ "');", true);
最佳答案
您可以使用 HiddenField
从客户端设置值,然后在服务器端访问它。
这是模型
<asp:HiddenField ID="hndSetFromJS" runat="server"></asp:HiddenField>
然后像这样设置值
document.getElementById("#<%= hndSetFromJS.ClientID %>").value = "yourValue";
或
$("#<%= hndSetFromJS.ClientID %>").val("yourValue"); // Jquery
关于javascript - ASP.NET C# 后端,用户是从 JavaScript 确认框中按了确定还是取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27494330/