Thanks Winista!
I assigned the code of the img to the Text property in the codebehind
and it worked.
rfv1.Text = GetValidatorText();
But the thing is I wanted to avoid using codebeind on this, otherwise I
could have used something like:
((HtmlImage)rfv1.Controls[0]).Src = GetThemeFile("error.jpg");
I wanted to use the GetThemeFile() method on properties of all sorts of
controls - like ImageButtons. It's a designer thing and I don't want to
put it in the codebehind.
I tried this:
<asp:RequiredFieldValidator ID="rfv1" Runat="server"
ControlToValidate="tx1" ErrorMessage="tx1 is empty."
Text='<%= GetValidatorText() %>' />
but again it doesn't work.
In fact, every time I've tried to use the <%= %construct it has
failed. Does it ever work?
Weirdly, this works:
<% rfv1.Text = GetValidatorText(); %>
<asp:RequiredFieldValidator ID="rfv1" Runat="server"
ControlToValidate="tx1" ErrorMessage="tx1 is empty." />
But only if the <%%block is in before the validator. What's up with
that? I thought the validator wouldn't be initialized back there.
Winista wrote:
Move the code related to "img" tag into ErrorText property. This probably
would work.
<de********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
Hello,
Here is my issue. I want to have validators which show an image when
the the control doesn't validate. Each user can select one of several
visual themes. For each theme the images are in a different
subdirectory.
So I need something like this:
<asp:RequiredFieldValidator ID="rfv1" Runat="server"
ControlToValidate="tx1" ErrorMessage="tx1 is empty.">
<img src='<%= GetThemeFile("error.jpg") %>' >
</asp:RequiredFieldValidator>
where GetStylesFile() is a method in a class, which all my pages
inherit and gets the proper path for an image, according to the theme
the user selected (saved in the Session).
Of course the peace of code above doesn't work (or I wouldn't be asking
for help), but I hope it illustrates what I am trying to do. Anyone
have ideas on how to achieve this?