开发者

if validation on the form field fails, set visible=true on a table row

开发者 https://www.devze.com 2022-12-27 02:44 出处:网络
I have a table row that has the error message in it. <tr run开发者_Go百科at=server id=trError1>

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

<tr run开发者_Go百科at=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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消