在网站的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);
答案 0 :(得分:1)
我想我会从客户端调用页面方法(带有webmethod属性的代码后面的方法)或使用ajax来调用Web服务。
由于确认操作是在客户端执行的,因此没有直接链接到您的服务器端cide
答案 1 :(得分:1)
您可以使用HiddenField
从客户端设置值,然后在服务器上访问它。
这是一个模型
<asp:HiddenField ID="hndSetFromJS" runat="server"></asp:HiddenField>
并设置像这样的值
document.getElementById("#<%= hndSetFromJS.ClientID %>").value = "yourValue";
或
$("#<%= hndSetFromJS.ClientID %>").val("yourValue"); // Jquery
答案 2 :(得分:1)
您可以在客户端
创建2个功能function functionOK()
{
//some code
}
function functionCancel()
{
//some code
}
并像这样更改你的代码
ClientScript.RegisterStartupScript(this.GetType(), "InvalidEntrySubTypeAlert", "if(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]
+ "')){ functionOK();} else{functionCancel()}", true);