Validator driving me nuts!

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I have a dropdownbox and a textbox.
If user enters something in the textbox BUT doesnt choose anything from the ddl, then i enable the validator in code behind...

This is what I have:
Code:
<asp:RequiredFieldValidator id="rvfActType" runat="server" [b]Enabled="False"[/b] InitialValue="---" Display="Dynamic" ControlToValidate="ddlActType22" ErrorMessage="RequiredFieldValidator">Required! </asp:RequiredFieldValidator>

In Code Behind, i have :

Code:
 rvfActType.Enabled = True
    rvfActType.Validate()
   [b] If Not rvfActType.IsValid Then [/b]
             Exit Sub
     End If

The value of NOT rvfActType.IsValid is False, so it should go down to Exit Sub but it doesnt!!!

Spent hours on this..what am i missing?
 
When I've needed to disable a validator, I never used "Enabled" for the property. You can turn it on & off using: EnableClientScript = "True/False"

I think that might be what you're missing.

In your case, in the code behind: rvfActType.EnableClientScript = False

Hope that helps... :cool:
 
This is not a good idea... because all ClientScript will stop working on client side ... that means that ALL validator won't work on client side and only on server side... it will have effect on the speed of execution.

You shall know that if EnableClientScript is set to true... it'll try to do everything on the client side before trying on server.

I'll search for your problem more in detail.
 
I ended up changing the design of my page per my coworker. But it would be good to know what the solution is.
 
Back
Top