在客户端使用自定义验证器?脚本错误时显示错误消息?

发布于 2024-08-11 00:18:09 字数 828 浏览 2 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独木成林 2024-08-18 00:18:09

将 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文