调用外部Javascript的UserControl CustomValidator
我有一个带有Datagrid的用户控件。当用户保存修改时,我需要通过调用Javascript文件进行比较来检查其中的一些文本框。(它将触发我的验证器,如果它出错,将显示一个弹出窗口) 我的ASPX:调用外部Javascript的UserControl CustomValidator,javascript,asp.net,customvalidator,Javascript,Asp.net,Customvalidator,我有一个带有Datagrid的用户控件。当用户保存修改时,我需要通过调用Javascript文件进行比较来检查其中的一些文本框。(它将触发我的验证器,如果它出错,将显示一个弹出窗口) 我的ASPX: <script type="text/javascript" src='/scripts/production_cost.js'></script> <ContentTemplate> <asp:DataGrid ID="ProdCostGrid" r
<script type="text/javascript" src='/scripts/production_cost.js'></script>
<ContentTemplate>
<asp:DataGrid ID="ProdCostGrid" runat="server" AutoGenerateColumns="False" BorderColor="#f0f0f0" BorderStyle="None" BorderWidth="0px" CellPadding="0">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="Id" HeaderText="Id"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
Amount: <asp:TextBox ID="ProductionCostLineField" Text='<%# ToText(Eval("ProductionCostEuro")) %>'
TabIndex="24" runat="server" Width="80px" MaxLength="13"></asp:TextBox> EUR
</ItemTemplate>
<ItemStyle Width="170px" HorizontalAlign="Right"></ItemStyle>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
//here I am suppose to put my Validator
<asp:CustomValidator ID="AmountCustomValidator" runat="server" Display="None" ErrorMessage="Amount must be filled" ClientValidationFunction="ValidateAmount" />
</ContentTemplate>
这只适用于aspx页面本身
@vdwwdooops我忘了删除它!javascript在我的aspx上运行,我需要将其分开并使用CustomValidator!复制粘贴。。。
function ValidateAmount(source, args) {
args.IsValid = true;
$('input[id*="ProductionCostLineField"]').blur(function () {
var amount = this.value;
$('input[id*="ProductionCostInvoiceToLineField"]').each(function () {
var textInvoicedBy = this.value;
if (amount == '' || amount == '0') {
} else {
if (this.value != '' || amount == '' || amount == '0') {
args.IsValid = true;
}
if ((amount != '' || amount != '0') && textInvoicedBy == '') {
alert("You must inform the field 'Invoiced By'");
args.IsValid = false;
}
}
});
});
}