views:

1660

answers:

3

If the page class property IsValid is read only, how can I set it using my own validation method?

So far all I've been able to do is set this property by calling Page.Validate().

How can I write my own functionality that will change the IsValid property just like Page.Validate() ??

thanks

+3  A: 

The isValid property is readonly because it is intended for use with server and client-side validators like the RequiredFieldValidator and RegularExpressionValidator. It's readonly because you can't force a page to be valid programmatically. "Valid" in this context means all the validators on the page evaluate to true.

Dave Swersky
A: 

Look at the asp:CustomValidator server control... MSDN Reference

HTHs, Charles

Charlino
+4  A: 

You don't set IsValid directly instead you call Validate() method of the Page object. If you have your custom validation methods then you need to use CustomValidator object and set that function in its server side validation property.

  <asp:CustomValidator ID="YourValidator" runat="server" SetFocusOnError="true"  
      ControlToValidate="YourControl"
        ClientValidationFunction="YOUR_JAVASCRIPT_FUNCTION" 
        OnServerValidate="YOUR_SERVER_VALIDATION_FUNCTION" Text="*" />
TheVillageIdiot