Asp.net 如何使用必需的字段验证器修复问题
我在listview的inserttemplate中插入了一个必需的字段验证器。假设验证器在用户单击“插入”时检查列表框中是否选择了值。但是,我在listview外部有一个搜索按钮,显示listview列,当单击该按钮时,将触发所需的字段验证程序。我只想在listview中单击insert按钮时触发它。这可能吗 位于ContentTemplate中的搜索按钮Asp.net 如何使用必需的字段验证器修复问题,asp.net,validation,listview,requiredfieldvalidator,Asp.net,Validation,Listview,Requiredfieldvalidator,我在listview的inserttemplate中插入了一个必需的字段验证器。假设验证器在用户单击“插入”时检查列表框中是否选择了值。但是,我在listview外部有一个搜索按钮,显示listview列,当单击该按钮时,将触发所需的字段验证程序。我只想在listview中单击insert按钮时触发它。这可能吗 位于ContentTemplate中的搜索按钮 <div style="padding-top: 5em; text-align: center; margin-left: au
<div style="padding-top: 5em; text-align: center; margin-left: auto; margin-right: auto; left: 0; right: 0; width:100%">
<b style="padding-right: .5em">FormSection </b>
<asp:TextBox ID="SectionSearchBox" runat="server"></asp:TextBox>
<b style="padding-left: 1em; padding-right: .5em">SubSection</b>
<asp:TextBox ID="SubSectionSearchBox" runat="server"></asp:TextBox>
<b style="padding-left: 1em; padding-right: .5em">Section Item</b>
<asp:TextBox ID="SectionItemSearchBox" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" Height="30px" runat="server" Text="Search" OnClick="SearchButton_Click" />
</div>
模板部分
分段
分项
位于listview的插入模板的内容模板中的必填字段验证器
<span style="color:red">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required Field!" ControlToValidate="formsection"></asp:RequiredFieldValidator>
</span>
<div style="height: auto; width: 250px; overflow: auto; border: solid; border-color: ActiveBorder" >
<asp:ListBox ID="formsection" runat="server" DataSourceID="FormSectionDataSource" DataTextField="FormSection" DataValueField="FormSectionID" AppendDataBoundItems="True" SelectedValue='<%# Bind("FormSectionID") %>' Height="150px">
<asp:ListItem Selected="True" Value=""><- please select -></asp:ListItem>
</asp:ListBox>
</div>
我在我使用的代码背后找到了答案
SearchButton.CausesValidation = false;
单击按钮时,不会触发验证。或者您可以将CausesValidation=false放入搜索按钮的asp标记中