other validation issues...

heralt

New Member
Hi all,<BR><BR>I'm trying to validate the input of a "input file" textbox.<BR><BR><input type="file" id="file1" runat="server"/><BR><asp:CustomValidator ControlToValidate="file1" OnServerValidate="CheckFileFormat" ErrorMessage="" Display="Dynamic" runat="server"/><BR><BR>Sub CheckFileFormat(Obj As Object, Args As ServerValidateEventArgs)<BR> Dim Ext As String = Args.Value<BR> If (Len(Ext) >= 5) Then <BR> Ext = UCase(Mid(Ext,Len(Ext)-2,3))<BR> If (Ext <> "GIF") Then<BR> Args.IsValid = False<BR> End If<BR> Else<BR> Args.IsValid = False<BR> End If<BR>End Sub<BR><BR>This does not prevent the page from being submitted even though the sub returns false back to the control. Any suggestions?<BR><BR>Thanks,<BR>D.<BR><BR>You need to supply a ClientValidationFunction to have it do that. You can read more about the ClientValidationFunction at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIWebControlsCustomValidatorClassCli entValidationFunctionTopic.asp<BR><BR>or you can pick up a copy of my latest book, which has a chapter on validation controls:<BR><BR>ASP.NET: Tips, Tutorials, and Code<BR>http://www.amazon.com/exec/obidos/ASIN/0672321432/4guysfromrollaco<BR><BR>Happy Programming!Why must it be client-side? Is it because it is a HtmlInputFile control?
 
Back
Top