help pls. textbox required only when checkbox is checked (help with validation)

E

Emiliano

Can anyone tell me how to or point me in the right direction for this?

I have a .aspx web for that uses <asp:requiredfieldvalidator... to
ensure fields are filled out. However I have field that is only
madatory if the user checks a certain checkbox. Any ideas on how to
validate on this condition only?

my code is below with no validation set:

<p><asp:checkbox runat="server" ID="TenantOrganization" /> Please
check the box if your organization or company is a tenant of the same
building where this garage is located.</p>

<p>If checked, please provide the name of your organization below:<br>

<asp:textbox runat="server" id="OrgName" Columns="35" MaxLength="50"
/>
 
J

Jim Cheshire [MSFT]

Emiliano,

You will need to use a CustomValidator to do this kind of validation. You
can still validate on the client.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
 
R

Rajesh.V

Easiest wud be to make the the page postback on chkbox being changed.
setting the autopostback to true and coding for the chkbox click event. In
the click event just enable the validator u are using with the textbox and
the textbox first testing whether the new state is checked.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top