I would like to load the ErrorMessage for my CustomValidator from a resource file.
I have my CustomValidator set up like so:
<asp:CustomValidator ID="cv1" runat="server" ControlToValidate="txt1"
ErrorMessage="TEXT TO BE LOCALIZED" OnServerValidate="cv1_Validate" />
And my validation method is as follows:
protected void cv1_Validate(object source, ServerValidateEventArgs e)
{
if (FalseCondition)
{
e.IsValid = false;
}
else
{
e.IsValid = true;
}
}
The validation works correctly, but I would like to have the ErrorMessage be pulled from my local resources file.
EDIT: I’m also curious if there is any way to do this using meta:resourcekey.
Assuming you have a local resource for your page (or control), this would be the way to do it
In case you get the text from a global resource file you should do something like this
Where
Stringsis the name of the file. This approach is called explicit localization.EDIT
You can use
meta:resourcekey. This is called implicit localization. You’ll need to have local resources since this approach is not valid for global resources.Source: MSDN