Asp:requiredfieldvalidator无效:o [英] Asp:requiredfieldvalidator is not working :o
本文介绍了Asp:requiredfieldvalidator无效:o的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家,
asp:RequiredFieldValidator无效。代码如下:
Hi Experts,
asp:RequiredFieldValidator is not working. Code is given below:
<tr id="trReportAgency" runat="server">
<td class="fieldlabel">
<asp:Label ID="lblAgency" runat="server" Text="Agency:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlAgency" runat="server" CssClass="listbox" Width="138px" />
<asp:RequiredFieldValidator ID="rqAgency" runat="server" ControlToValidate="ddlAgency"
CssClass="validatorIndicator" Display="Dynamic" ErrorMessage="Please select agency."
InitialValue="-1" Text="i" ToolTip="Please select agency.">
</asp:RequiredFieldValidator>
</td>
</tr>
我们非常感谢任何评论或建议。
我尝试过:
嗨专家,
asp:RequiredFieldValidator不起作用。代码如下:
Any comments or suggestion is highly appreciated.
What I have tried:
Hi Experts,
asp:RequiredFieldValidator is not working. Code is given below:
<tr id="trReportAgency" runat="server">
<td class="fieldlabel">
<asp:Label ID="lblAgency" runat="server" Text="Agency:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlAgency" runat="server" CssClass="listbox" Width="138px" />
<asp:RequiredFieldValidator ID="rqAgency" runat="server" ControlToValidate="ddlAgency"
CssClass="validatorIndicator" Display="Dynamic" ErrorMessage="Please select agency."
InitialValue="-1" Text="i" ToolTip="Please select agency.">
</asp:RequiredFieldValidator>
</td>
</tr>
我们非常感谢任何意见或建议。
Any comments or suggestion is highly appreciated.
推荐答案
使用下面的代码,这可以帮到你:
Use the below code, this may help you:
<table>
<tr id="trReportAgency" runat="server">
<td class="fieldlabel">
<asp:Label ID="lblAgency" runat="server" Text="Agency:" />
</td>
<td>
<asp:DropDownList ID="ddlAgency" runat="server" CssClass="listbox" Width="138px" >
<asp:ListItem Text="Select" Value="-1"></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rqAgency" runat="server" ControlToValidate="ddlAgency"
CssClass="validatorIndicator" Display="Dynamic" ErrorMessage="Please select agency."
InitialValue="-1" Text="Please select agency" ToolTip="Please select agency." />
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="btnPrint_Click" />
</td>
</tr>
</table>
谢谢,
Thanks,
如果我们使CausesValidation属性为true,那么它正在工作。
If we make "CausesValidation" property is "true" then it is working.
<asp:Button ID="btnPrint" runat="server" CausesValidation="true" Text="Print" OnClick="btnPrint_Click" />
CausesValidation默认值为true。如果你把它弄错,那么你强行说你不想要验证。
参考:
Button.CausesValidation属性(System.Web.UI.WebControls ) [ ^ ]
CausesValidation default value is true. If you make this false then you forcefully saying that you do not want validation to fire.
Reference:
Button.CausesValidation Property (System.Web.UI.WebControls)[^]
这篇关于Asp:requiredfieldvalidator无效:o的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文