CustomValidator not keeping its isValid=False value
Posted on 2005-03-19
I am using a custom control to validate a file upload control on a webpage. When the file upload fails validation I set the IsValid property of the custom validator to false.
The aspx code is as follows for the custom validator:
<asp:CustomValidator CssClass="validatorStyle" id="ImageUploadValidator" ControlToValidate="ImageFile"
runat="server" ErrorMessage="Invalid File Selected For Upload"></asp:CustomValidator>
In the codebehind :
When the page is submitted with a [submit] button I call a function ValidateThePage which does a number of things including checking for the validity of the postedfile.inputstream:
If (ImageFile.PostedFile.InputStream.Length = 0 And hdnCurrentPage.Value = "3") Then
ImageUploadValidator.IsValid = False
When I test for the validation of the page by checking the value of Page.IsValid i get the following error:
Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control with CausesValidation=True or after a call to Page.Validate
When I call the page.validate method before checking for page.isvalid property the isvalid property of the custom validator is set to true from false.
Can anyone think of any reason this is not working for me?
Thanks in advance,