我被要求将 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/