在客户端使用自定义验证器?脚本错误时显示错误消息?
我对 ASP.NET 客户端的自定义验证器有一个有问题的问题?
这是我的文件上传控件和自定义验证器,用于检查上传的文件是否为文档!!!!
<asp:FileUpload Id="fu_1" runat="server" />
asp:CustomValidator ID="cv_fu1" runat="server" ControlToValidate="fu_1" ValidationGroup="submit" ClientValidationFunction="file_upload" text="Pls!!! uploat doc file only"> </asp:CustomValidator>
这是我的 javascript 函数,用于检查上传文件是否为 doc!!!!!!
function file_upload()
{
var file1 = document.getElementById("fu_1").value;
len_file1 = file1.length;
var len1_name = file1.substring(len_file1 - 3,len_file1);
if(len1_name != 'doc')
{
alert("wrong file format");
}
}
我想将错误消息放在自定义验证器中代替警报消息..javascript..
像其他验证器的错误消息一样..我将错误放在上面验证器的文本属性中..请在自定义验证器属性中检查它.. 我想显示该错误...
我检查了与此相关的所有问题..但我找不到我想要的..
I have one problematic question on custom validator at client side in asp.net?
This is my fileupload control and customvalidator to check that uploaded file is doc or not!!!!
<asp:FileUpload Id="fu_1" runat="server" />
asp:CustomValidator ID="cv_fu1" runat="server" ControlToValidate="fu_1" ValidationGroup="submit" ClientValidationFunction="file_upload" text="Pls!!! uploat doc file only"> </asp:CustomValidator>
This is my javascript function for checking that upload file is doc or not!!!!!!
function file_upload()
{
var file1 = document.getElementById("fu_1").value;
len_file1 = file1.length;
var len1_name = file1.substring(len_file1 - 3,len_file1);
if(len1_name != 'doc')
{
alert("wrong file format");
}
}
i want to put error message in custom validator in place of alert message..of javascript..
like other validator's error message.. i put error in text property of validator above..pls check it in custom validator property..
that error i want to show...
i check all question related to this .. but i cant find that i want..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 file_upload 签名修改为“function file_upload(sender, args)”
在函数内,根据您所需的逻辑设置 args.IsValid = true 或 false
另外,将 ClientValidationFunction 设置为“file_upload”(不带括号)
Modify the file_upload signature to be "function file_upload(sender, args)"
Within the function, set args.IsValid = true or false depending on your required logic
Also, set the ClientValidationFunction to "file_upload" (without the brackets)