views:

388

answers:

1

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..

+5  A: 

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)

zincorp
i have dont that.. but not done.. man.
Sikender
Set the ErrorMessage property on the custom validator
zincorp