ASP.NET - 必需的字段验证器在列表框中给出假阴性错误
背景:我有一个捆绑列表框,一旦通过网络服务选择了运营商,它就会继承运营商列表框的值。
- 我在按钮上有一个validationGroup,我在点击处理程序上使用了Page.IsValid,它显示“Nothing”。
- 当我在 IE8 中选择不同的运营商时,它会重置其他表单值,但在 IE9 中不会。
- 如果 lbCarriers 上的 Autopost=false,捆绑列表框将不会加载任何数据。
- 在“lbCarriers”中使用 CausesValidation="true" 时,捆绑列表框也不会加载任何数据 您知道如何使用 Ajax 来做到这一点吗?
- 你知道我如何使用 Ajax 来做到这一点吗?
问题:当我选择了捆绑包时,在捆绑包列表框中使用必填字段验证器会返回错误错误。当我单击“发送”按钮时,收到“选择至少 1 个捆绑包”错误消息,但邀请仍会发出“我收到一封电子邮件”。
下面是应用程序的屏幕截图:
default.aspx 页面上的 asp.net 代码:
<tr>
<td class="style5">
Carrier:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Carriers</font></td>
<td bgcolor="#ffffff" class="style7">
<asp:ListBox ID="lbCarriers" SelectionMode="Multiple" AutoPostBack="true"
runat="server" Height="86px" Width="250px" ValidationGroup="ValidationGroup">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="CarrierValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Carrier" ControlToValidate="lbCarriers"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Bundles:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Bundles</font></td>
<td bgcolor="#ffffff" class="style6">
<asp:ListBox ID="bundles" SelectionMode="Multiple" runat="server" Height="86px"
Width="250px" Enabled="True"
ValidationGroup="ValidationGroup" CausesValidation="True">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="BundleValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Bundle" ControlToValidate="bundles"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<asp:Button ID="Send_Button" runat="server"
Text="Send Invitation" ValidationGroup="ValidationGroup" Width="123px"/>
<br />
<asp:Label ID="Send_Success" runat="server" Text="Invitation sent!" Visible="false"></asp:Label>
<br />
<asp:ValidationSummary ID="ValidationSummary" runat="server" ForeColor="Red"
ValidationGroup="ValidationGroup" />
问题:有哪些替代代码或工作 -对于这个问题你有推荐吗?
感谢您的关注!
Background: I have a bundles listbox that inherits values from the carriers listbox once a carrier is selected via a web service.
- I have a validationGroup on the button, I used Page.IsValid on the click handler and it says "Nothing".
- When i select different carriers in IE8 it resets the other form values but not in IE9.
- With Autopost=false on the lbCarriers, the Bundles listbox wont load any data.
- With CausesValidation="true" in "lbCarriers", Bundles listbox wont load any data either Do you know how to do that w Ajax?
- Do you know how I could do this w/ Ajax?
Problem: Using the required field validator on the bundles listbox is returning an a false erorr when I have bundles selected. When I click the Send Button, I get the "Select At Least 1 Bundle" Error Message but the invitation still sends out an i get an email.
Here's a screenshot of the application:
asp.net code on default.aspx page:
<tr>
<td class="style5">
Carrier:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Carriers</font></td>
<td bgcolor="#ffffff" class="style7">
<asp:ListBox ID="lbCarriers" SelectionMode="Multiple" AutoPostBack="true"
runat="server" Height="86px" Width="250px" ValidationGroup="ValidationGroup">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="CarrierValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Carrier" ControlToValidate="lbCarriers"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Bundles:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Bundles</font></td>
<td bgcolor="#ffffff" class="style6">
<asp:ListBox ID="bundles" SelectionMode="Multiple" runat="server" Height="86px"
Width="250px" Enabled="True"
ValidationGroup="ValidationGroup" CausesValidation="True">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="BundleValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Bundle" ControlToValidate="bundles"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<asp:Button ID="Send_Button" runat="server"
Text="Send Invitation" ValidationGroup="ValidationGroup" Width="123px"/>
<br />
<asp:Label ID="Send_Success" runat="server" Text="Invitation sent!" Visible="false"></asp:Label>
<br />
<asp:ValidationSummary ID="ValidationSummary" runat="server" ForeColor="Red"
ValidationGroup="ValidationGroup" />
Question: What alternate code or work-around do you recommend for this issue?
Thanks for looking!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
在"lbCarriers"
中添加CausesValidation="true"
我已从第一个列表框即删除了
Autopost="true"
“lbCarriers”现在正在工作。EDIT:
AddCausesValidation="true"
in"lbCarriers"
I have removed
Autopost="true"
from first listbox i.e. "lbCarriers" and it is working now.