0

In the following css

.garbage {
    display: none;
}
.garbage[style*=visible] + input,
.garbage[style*=visible] + select,
.garbage[style*=visible] + textarea {
    background-color: #ffcccc;
    border: 1px solid #ff0000;
}

the asp:*Validator is before a form. How do I change the css so that the validator can be after the form.

The css (https://stackoverflow.com/a/28886219/6346811) works for the following:

<asp:RequiredFieldValidator ID="blah" runat="server" 
    ErrorMessage="Please fill out this field" CssClass="garbage" 
    ControlToValidate="txt_blah" ValidationGroup="blah" 
    SetFocusOnError="True"></asp:RequiredFieldValidator>

<asp:TextBox ID="txt_DateBirth" runat="server"></asp:TextBox>

But it doesn't work for

<asp:TextBox ID="txt_DateBirth" runat="server"></asp:TextBox>        

<asp:RequiredFieldValidator ID="blah" runat="server" 
    ErrorMessage="Please fill out this field" CssClass="garbage" 
    ControlToValidate="txt_blah" ValidationGroup="blah" 
    SetFocusOnError="True"></asp:RequiredFieldValidator>
Community
  • 1
  • 1
Aaron Donald
  • 13
  • 1
  • 3
  • 1
    Instead of creating a link to an image to an answer with some code (huh!), just copy over the code together with the link to the post where it came from. This way you would bring all relevant code to your post, get rid of some thrid-party image hosting services, and attribute the original author – Andrei May 17 '16 at 16:44
  • Thanks for your critique! First time poster. – Aaron Donald May 17 '16 at 17:00

1 Answers1

0

Notice + sign in the css you linked to. It means "directly followed by". Since your markup is a reverse, all you need to do is reverse the selector:

input + .garbage[style*=visible] {
Andrei
  • 55,890
  • 9
  • 87
  • 108