admin管理员组文章数量:1287832
I can't get this CustomValidator working.
In the <head>:
<script language="javascript" type="text/javascript">
function ValidateFile(sender, args){
alert("Hi");
args.IsValid = document.getElementById("fuFile").value != "" ||
document.getElementById("c101_c7").value != "";
}
</script>
In the body:
<asp:FileUpload ID="fuFile" runat="server" size="70"/>
<asp:TextBox ID="c101_c7" class="textbox" runat="server"/>
<asp:CustomValidator ID="vldFile" runat="server" ClientValidationFunction="ValidateFile"
ErrorMessage="You must either upload a file or provide a URL of a file."></asp:CustomValidator>
What should be in the args.IsValid if either the FileUpload or TextBox has to be filled in?
I can't get this CustomValidator working.
In the <head>:
<script language="javascript" type="text/javascript">
function ValidateFile(sender, args){
alert("Hi");
args.IsValid = document.getElementById("fuFile").value != "" ||
document.getElementById("c101_c7").value != "";
}
</script>
In the body:
<asp:FileUpload ID="fuFile" runat="server" size="70"/>
<asp:TextBox ID="c101_c7" class="textbox" runat="server"/>
<asp:CustomValidator ID="vldFile" runat="server" ClientValidationFunction="ValidateFile"
ErrorMessage="You must either upload a file or provide a URL of a file."></asp:CustomValidator>
What should be in the args.IsValid if either the FileUpload or TextBox has to be filled in?
Share Improve this question edited Apr 8, 2009 at 3:46 Aximili asked Apr 8, 2009 at 3:04 AximiliAximili 29.5k57 gold badges162 silver badges226 bronze badges5 Answers
Reset to default 5I find it helpful to actually let the code behind tell your JavaScript code what the client-side ID of the control is, since it's possible it's different than what you would think (based on what ASP .NET decides to do):
document.getElementById('<%=fuFile.ClientID %>');
<script type="text/javascript">
//<![CDATA[
function validateField(sender, args) {
var regExp = /(^[a-zA-Z]{2,50})$/;
var val = document.getElementById(sender.controltovalidate).value;
args.IsValid = regExp.test(val);
}
//]]>
</script>
are you just using a normal button to trigger the validation?
Are you implementing validationgroups anywhere else in this code?
You need to set the ControlToValidate Property on the custom validator. Currently the validator is not hooked up to any control.
Also, I'm sure you just didn't post this part of the markup, but you need to have a control that does a postback and causes validation as part of its postback. A button will work for this.
This works
document.getElementById("ctl00_ContentPlaceHolder1_fuFile").value
本文标签: netASPNET CustomValidator client sideStack Overflow
版权声明:本文标题:.net - ASP.NET CustomValidator client side - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741322848a2372307.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论