validation block - class on the page?

Feb 5, 2010 at 8:03 AM

hi all,

i want to know how to have the validation block working without calling a class that is in an external file (app_code/....)

say i have the following..

<cc2:PropertyProxyValidator ID="val_file_upload" runat="server" PropertyName="UploadFileName"
ValidationGroup="UploadFileValidation" ControlToValidate="file0" SourceTypeName="file_upload_validation"
Display="Dynamic" />

and my code behind logic are...

Public Class file_upload_validation

        Dim _UploadFileName As String = Nothing
        <StringLengthValidator(1, 255, MessageTemplate:="Please Select a File to Upload")> _
        <ContainsCharactersValidator("<>", ContainsCharacters.All, MessageTemplate:="Please remove '<>' from the file name", negated:=True)> _
        Public Property UploadFileName() As String

            Get
                Return _UploadFileName
            End Get

            Set(ByVal _value As String)
                _UploadFileName = _value
            End Set

        End Property

    End Class

what must i do so that the validation will use the class in my page?

I don't want to create a file in the app_code folder, i want to link SourceTypeName="file_upload_validation" to my page's class instead

thanks

lindows

 

Coordinator
Feb 12, 2010 at 2:52 PM
Edited Feb 12, 2010 at 2:54 PM

Hi Lindows,

 

I have a feeling the solution has something to do with namespaces.  I notice that are not using any.  When your page is compiled your code behind will be compiled to a dll in the bin folder (or ASP.NET Temporary Files folder) along with any code you might have in the app_code folder.  Depending on which version of ASP.NET, and other deployment settings, you are using depends on where this dll sits (local bin or ASP.NET Temp folder under C:\Windows\Microsoft.NET\frameworks\...etc and whether it is one for the application or one per web page.  To find your class there has to be enough type information to find it and no other classes of the same name.

Try adding a namespace (otherwise I think you get one automatically assigned), for example "MyPages", then your SourceTypeName would become "MyPages.file_upload_validation"

Cheers...   Steve