Checking too see if client side validation functions will be sent to the browser

  • Thread starter Thread starter Darrel
  • Start date Start date
D

Darrel

I am creating a server control that inherits from a command button.
The problem is it needs to generate different client side script,
depending on whether validators will get added to the page or not. On
the server side, is there some way I can check to see if the asp.net
page will be sending to the client the validation client side script
or not. Currenly I have to loop through every control on the page to
see if any of them is a validator. (A way that seems very inefficent.)
Is there a better way? I want to able to say, if any client side
validation will be done do this, otherwise do this.
 
Darrel,

you could check Page.Validators collection to see how many
validators are on the page.

And whether the validation code is appended to the output -
I believe that validation script is generated only for
IE - so checking the Request.Browser.Type.StartsWith("IE")
will get you the rest.

Hope this helps.
 
Back
Top