javascript - 向用户呈现多条确认消息的最佳方式

标签 javascript c# asp.net webforms

我被要求将 VB6 应用程序转换为 WebForms 环境(C# .NET v4.5)。单击“保存”按钮时,现有应用程序会显示多条确认消息。

EG. "You have entered X, which is less than Y. Are you sure?"

他们希望保留此功能,但我对这种向用户发送(可能)10 多个问题的垃圾邮件的方法感到不舒服,用户必须点击这些问题才能保存。更不用说现代浏览器允许用户禁用多个弹出窗口。

那么对于这种情况,有没有人有更“最佳实践”的方法?

最佳答案

您可以使用 ASP.Net <asp:ValidationSummery>控制以达到您的目的。 请查找以下代码以供引用。

<!DOCTYPE html>
<html>
<body>

<form runat="server">
<table>
<tr>
<td>
<table bgcolor="#b0c4de" cellspacing="10">
   <tr>
     <td align="right">Name:</td>
     <td><asp:TextBox id="txt_name" runat="server"/></td>
     <td>
     <asp:RequiredFieldValidator
     ControlToValidate="txt_name" 
     ErrorMessage="Please Enter Name"
     Text="*" 
     runat="server"/>
     </td>
   </tr>
   <tr>
     <td align="right">Travel Type:</td>
     <td>
     <asp:RadioButtonList id="rlist_type" 
     RepeatLayout="Flow"
     runat="server">
     <asp:ListItem>Bus</asp:ListItem>
     <asp:ListItem>Train</asp:ListItem>
     <asp:ListItem>Flight</asp:ListItem>
     </asp:RadioButtonList>
     </td>
     <td>
     <asp:RequiredFieldValidator
     ControlToValidate="rlist_type"
     ErrorMessage="Please Select Travel Type"
     InitialValue=""
     Text="*"
     runat="server"/>
     </td>
   </tr>
   <tr>
     <td></td>
     <td><asp:Button id="b1" Text="Submit" runat="server"/></td>
     <td></td>
   </tr>
</table>
</td>
</tr>
</table>
<asp:ValidationSummary
ShowMessageBox="true"
ShowSummary="false"
HeaderText="You must enter a value in the following fields:"
EnableClientScript="true"
runat="server"/>
</form>

</body>
</html>

关于javascript - 向用户呈现多条确认消息的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27976439/

相关文章:

javascript - 使用同一对象中其他函数的对象函数

c# - 如何编译完成的 C# 项目然后在 Visual Studio 之外运行?

c# - 如何让 SWIG 在 C# 中处理 utf8 字符串?

asp.net - 是否有太多内部链接(菜单链接、页脚链接等)被​​视为 "duplicate content"?

javascript - 在 Backbone.js 中使用模型对集合进行过滤/排序

javascript - onmouseover 和 onmouseout 调整图像大小

javascript - string.split() 返回额外的项目(函数)

c# - NHibernate - 在哪里..在..和 future

c# - 有没有一种使用 ASP.NET 验证器比较复选框和文本框的优雅方法?

c# - 允许用户在 FullCalendar 资源 View 的每个单元格中仅添加一个事件