dynamic validator images

Discussion in 'ASP .Net' started by delta.emil@gmail.com, Jul 14, 2006.

  1. Guest

    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?
     
    , Jul 14, 2006
    #1
    1. Advertising

  2. delta Guest

    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.
     
    delta, Jul 14, 2006
    #2
    1. Advertising

  3. Winista Guest

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

    <> wrote in message
    news:...
    > 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?
    >
     
    Winista, Jul 14, 2006
    #3
  4. delta Guest

    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.
    >
    > <> wrote in message
    > news:...
    > > 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?
    > >
     
    delta, Jul 15, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. coollzh
    Replies:
    0
    Views:
    384
    coollzh
    Jun 3, 2004
  2. Nergal

    Dynamic validator Query

    Nergal, Jan 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,179
    Nergal
    Jan 24, 2005
  3. =?Utf-8?B?U3RldmUgV29uZGVyZnVs?=

    ASP.NET 1.1 Bug - Dynamic RE Validator

    =?Utf-8?B?U3RldmUgV29uZGVyZnVs?=, Mar 1, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    471
    =?Utf-8?B?U3RldmUgV29uZGVyZnVs?=
    Mar 1, 2006
  4. =?Utf-8?B?TWlrZSBDb2xsaW5z?=

    Dynamic Validator Help Please

    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Nov 15, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    348
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=
    Nov 15, 2006
  5. Replies:
    4
    Views:
    915
    Richter~9.6
    Feb 13, 2007
Loading...

Share This Page