Wednesday, September 3, 2008

Change ASP.NET Validator ErrorMessage Using Javascript

This Post helps You in Changing Validatiors Errormessage Dynamically One Upon in I was Developing Video Upload Module Using Teleric File Upload. I want that FileUpload input should not blank .as well Should Accept Only .FLV Files.As i can be able to useRequireFieldValidatior .So I Use CustomValidator . In CustomeValidator Using ClientValidationFunction="validateRadVideoUpload" Property U can write fileInputs[0].value.length <= 1 to validate for '"Required Filed". So what For it should Contain .FLV at the end?? It Is easy to check Using Regular Expression. Now Problem Is Here. How will you change ErrorMessage Of CustomValidator To "Required Valid File" If user Enter file with invalid Extension. I have To Use Javascript Right?? Here is The Solutions. var Validate_VideoclientId='<%= Validate_Video.ClientID %>'; var tmp_Validate_VideoclientId = document.all ? document.all[Validate_VideoclientId] : document.getElementById(Validate_VideoclientId); tmp_Validate_VideoclientId.errormessage = "Please select valid VideoFile"; This the way u can change ErrorMessage Property of ValidationControl Dynamically. Nees Morehelp?? Write me on This Blog..Thanks