views:

30

answers:

2

I have a table row that has the error message in it.

<tr runat=server id=trError1>
<td>...</td>
</tr>

Now if someone forgets to enter text or bad text in a textbox, I want this form field to be set to visible.

Can I use a asp.net validator for this or?

+1  A: 

Sure, if you use the CustomValidator you can specify your own server and client-side callback function which can do pretty much anything (including showing/hiding table rows).

EDIT Looks like your table marks items as visible or not server side so you'll need to do something like this:

Markup

<asp:CustomValidator id="CustomValidator1"
       ControlToValidate="Text1"
       OnServerValidate="ServerValidation"
       runat="server"/>

Code behind

void ServerValidation(object source, ServerValidateEventArgs args)
{
    // your validation code here, 
    //set args.IsValid to true/false

    trError1.Visible = !args.IsValid;
}

Though if you're using your table to show a list of errors, you should take a look at the ValidationSummary control.

R0MANARMY
A: 

I'm not as familiar with the validation controls, but you could also set the message (or the visibility) of the control with a check when the page is submitted or a button clicked. Something to the effect of

if txtMyBox.text = "" then
   lblMessage.text = "Error.."
end if

Or adjust the visibility/CSS class at that point to make your label visible.

Thyamine