javascript - UserControl CustomValidator 调用外部 Javascript
问题描述
我有一个带有 Datagrid 的用户控件。当用户保存其修改时,我需要通过调用我的 Javascript 文件进行比较来检查其中的一些文本框。(它会触发我的验证器,如果错误会弹出一个窗口)
我的 ASPX:
<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>
我的 Javascript 在不同的文件夹中:
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;
}
}
});
});
}
解决方案
推荐阅读
- c++ - Matlab 编码器:如何强制变量具有变量:inf 大小
- python-3.x - python pandas异常值删除-由于错误而无法删除
- azure-data-factory - Azure 数据工厂:使用复制活动设置复制文件数量的限制
- javascript - 将标记添加到传单中的用户位置
- ckeditor - Typo3 关闭并开始一个新段落
在每个
新闻扩展的正文中 - openmdao - 什么时候适合使用元模型而不是昂贵的分析?
- c - 在 Linux(RedHat) 中,C 函数 malloc_stats() 显示与 /proc/ 不同的值
/stat 常驻内存大小 - javascript - 一起使用 scroll-ID DOM-event
- python - Pandas:将年度数据转换为十年数据
- flutter - 在 null 上调用了方法“_mulFromInteger”