dynamic validator images

D

delta.emil

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?
 
D

delta

I forgot to mention - I'm using .NET framework v1.1 and I'm not allowed
to upgrade to v2, so ASP.NET 2 solutions won't help me.
 
W

Winista

Move the code related to "img" tag into ErrorText property. This probably
would work.
 
D

delta

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top