.NETGURU
Custom Validator
Messages   Related Types
This message was discovered on ASPFriends.com 'aspng-validators' list.


Wes Loukota
Hi all,

I am try to trying restrict upload to only .doc files. I have looked through the documentation and was really confused by the syntax. I attempted to use a regular expression validator but it doesn't seem to allow custom regex, unless I don't have the proper syntax. Below is the code for the custom validator I am trying to use. I've set the sub below as a break point and tried stepping through the debugger (in VS.Net ver 7.0.9466), but it doesn't break at that point and the validator summary message box pops up declaring "The only acceptable files for upload are .doc files !" which is the error message I set.

Any suggestions on how to fix this or where to look would be appreciated.

Thanks,

Wes

Sub FileValidation(ByVal source As Object, ByVal args As ServerValidateEventArgs)

Try

If uplFile.Value = "(\w,\W)*\.\d\o\c" Then

args.IsValid = True

End If

Catch ex As Exception

args.IsValid = False

End Try

End Sub

---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
Reply to this message...
 
    
Glavich, Paul C
Hi all,

I am try to trying restrict upload to only .doc files. I have looked through
the documentation and was really confused by the syntax. I attempted to use
a regular expression validator but it doesn't seem to allow custom regex,
unless I don't have the proper syntax. Below is the code for the custom
validator I am trying to use. I've set the sub below as a break point and
tried stepping through the debugger (in VS.Net ver 7.0.9466), but it
doesn't break at that point and the validator summary message box pops up
declaring "The only acceptable files for upload are .doc files !" which is
the error message I set.

Any suggestions on how to fix this or where to look would be appreciated.

Thanks,

Wes

Sub FileValidation(ByVal source As Object, ByVal args As
ServerValidateEventArgs)

Try

If uplFile.Value = "(\w,\W)*\.\d\o\c" Then

args.IsValid = True

End If

Catch ex As Exception

args.IsValid = False

End Try

End Sub

---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes --0-697297990-1026738054=:46284
Content-Type: text/html; charset=us-ascii

<P>Hi all,</P>
<P>I am try to trying restrict upload to only .doc files. I have looked
through the documentation and was really confused by the syntax. I attempted
to use a regular expression validator but it doesn't seem to allow
custom regex, unless I don't have the proper syntax. Below is the code for
the custom validator I am trying to use. I've set the sub below as a break
point and  tried stepping through the debugger (in  VS.Net ver
7.0.9466), but it doesn't break at that point and the validator summary
message box pops up declaring "The only acceptable files for upload are .doc
files !" which is the error message I set.</P> <P>Any suggestions on how to
fix this or where to look would be appreciated.</P> <P>Thanks,</P>
<P>Wes</P><FONT size=2> <P></FONT><FONT color=#0000ff size=2>Sub</FONT><FONT
size=2> FileValidation(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT
size=2> source </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2>
</FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT
color=#0000ff size=2>ByVal</FONT><FONT size=2> args </FONT><FONT
color=#0000ff size=2>As</FONT><FONT size=2> ServerValidateEventArgs)</P>
<P></FONT><FONT color=#0000ff size=2>Try</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> uplFile.Value "(\w,\W)*\.\d\o\c" </FONT><FONT color=#0000ff size=2>Then</P></FONT><FONT
size=2> <P>args.IsValid = </FONT><FONT color=#0000ff
size=2>True</P></FONT><FONT size=2> <P></FONT><FONT color=#0000ff
size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>If</P></FONT><FONT size=2> <P></FONT><FONT color=#0000ff
size=2>Catch</FONT><FONT size=2> ex </FONT><FONT color=#0000ff
size=2>As</FONT><FONT size=2> Exception</P> <P>args.IsValid = </FONT><FONT
color=#0000ff size=2>False</P></FONT><FONT size=2> <P></FONT><FONT
color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>Try</P></FONT><FONT size=2> <P></FONT><FONT color=#0000ff
size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>Sub</P></FONT><p><br><hr size=1><b>Do You Yahoo!?</b><br> <a
href="http://autos.yahoo.com/";>Yahoo! Autos</a> - Get free new car price
quotes
--0-697297990-1026738054=:46284--
| [aspng-validators] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspng-validators.asp = JOIN/QUIT
Reply to this message...
 
    
Wes Loukota
Paul, Thanks for the suggestion. I couldn't get it to work but I did get uplFile.PostedFile.FileName.EndsWith(".doc") = True to work in identifying the file, but I can't get it to work with the custom validator(code below). I've set the ClientValidationFunction property to FileValidation. I've read through the CustomValidator.ClientValidationFunction Property doc but didn't quite understand what they were doing. Can you help.
Thanks,
Wes

Private Function FileValidation(ByVal source As Object, ByVal args As ServerValidateEventArgs)

Try

If uplFile.PostedFile.FileName.EndsWith(".doc") = True Then

reFileType.IsValid = True

End If

Catch ex As Exception

reFileType.IsValid = False

End Try

End Function

"Glavich, Paul C" <Click here to reveal e-mail address> wrote: The regex validator should work, try fiddling with the regex expression. I
personally hate these and am not good at them so wont even try coming up
with a good regex expression. Alternatively, in your code, you could check
the extension with

If
String.Compare(uplFile.Value.Substring(uplFile.Value.Substring.length-4,4),"
.doc") = true then...

* Paul Glavich
Professional Web Services
Email: Click here to reveal e-mail address
Urgent Messages: Email Click here to reveal e-mail address and place urgent in subject line.
(Currently no fixed phone or street address)

-----Original Message-----
From: Wes Loukota [mailto:Click here to reveal e-mail address]
Sent: Monday, 15 July 2002 11:01 PM
To: aspng-validators
Subject: [aspng-validators] Custom Validator

-- Moved from [aspngfreeforall] to [aspng-validators] by Tim Musschoot
--

--0-697297990-1026738054=:46284
Content-Type: text/plain; charset=us-ascii

Hi all,

I am try to trying restrict upload to only .doc files. I have looked through
the documentation and was really confused by the syntax. I attempted to use
a regular expression validator but it doesn't seem to allow custom regex,
unless I don't have the proper syntax. Below is the code for the custom
validator I am trying to use. I've set the sub below as a break point and
tried stepping through the debugger (in VS.Net ver 7.0.9466), but it
doesn't break at that point and the validator summary message box pops up
declaring "The only acceptable files for upload are .doc files !" which is
the error message I set.

Any suggestions on how to fix this or where to look would be appreciated.

Thanks,

Wes

Sub FileValidation(ByVal source As Object, ByVal args As
ServerValidateEventArgs)

Try

If uplFile.Value = "(\w,\W)*\.\d\o\c" Then

args.IsValid = True

End If

Catch ex As Exception

args.IsValid = False

End Try

End Sub

---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes --0-697297990-1026738054=:46284
Content-Type: text/html; charset=us-ascii

Hi all,

I am try to trying restrict upload to only .doc files. I have looked
through the documentation and was really confused by the syntax. I attempted
to use a regular expression validator but it doesn't seem to allow
custom regex, unless I don't have the proper syntax. Below is the code for
the custom validator I am trying to use. I've set the sub below as a break
point and tried stepping through the debugger (in VS.Net ver
7.0.9466), but it doesn't break at that point and the validator summary
message box pops up declaring "The only acceptable files for upload are .doc
files !" which is the error message I set.

Any suggestions on how to
fix this or where to look would be appreciated.

Thanks,

Wes

Subsize=2> FileValidation(ByValsize=2> source As
Object, color=#0000ff size=2>ByVal args color=#0000ff size=2>As ServerValidateEventArgs)

Try

If uplFile.Value "(\w,\W)*\.\d\o\c" Then
size=2>
args.IsValid = size=2>True

size=2>End size=2>If

size=2>Catch ex size=2>As Exception

args.IsValid = color=#0000ff size=2>False

color=#0000ff size=2>End size=2>Try

size=2>End size=2>Sub

---------------------------------
Do You Yahoo!?
href="http://autos.yahoo.com/";>Yahoo! Autos - Get free new car price
quotes
--0-697297990-1026738054=:46284--
| [aspng-validators] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspng-validators.asp = JOIN/QUIT

| [aspng-validators] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspng-validators.asp = JOIN/QUIT

Be sure to visit The Top Dog at http://the72bulldogs.com

---------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access
Reply to this message...
 
    
Glavich, Paul C
Wes, the client validation function should be a piece of Javascript that
exists within the web page (ie. client side). it should be something like
this :-

<script language="javascript">
function FileValidation(oSrc, args)
{
args.IsValid = false;
// do your test for the filename extension which will be in args.value
property
if (args.value.length > 0)
{
// test for .doc extension (I cant remember the javascript for
string manipulations...), pos, substr...?
if (file contains a .doc extnesion)
args.IsValid = true;
}
}
</script>

Note that the above is pseudo code but should give you an idea of how to go
about it.

* Paul Glavich
Professional Web Services
Email: <mailto:Click here to reveal e-mail address> Click here to reveal e-mail address
Urgent Messages: Email <mailto:Click here to reveal e-mail address> Click here to reveal e-mail address and
place urgent in subject line.
(Currently no fixed phone or street address)
-----Original Message-----
From: Wes Loukota [mailto:Click here to reveal e-mail address]
Sent: Wednesday, 17 July 2002 12:54 AM
To: aspng-validators
Subject: [aspng-validators] RE: Custom Validator

Paul, Thanks for the suggestion. I couldn't get it to work but I did get
uplFile.PostedFile.FileName.EndsWith(".doc") = True to work in identifying
the file, but I can't get it to work with the custom validator(code below).
I've set the ClientValidationFunction property to FileValidation. I've read
through the CustomValidator.ClientValidationFunction Property doc but didn't
quite understand what they were doing. Can you help.

Thanks,

Wes

Private Function FileValidation(ByVal source As Object, ByVal args As
ServerValidateEventArgs)

Try

If uplFile.PostedFile.FileName.EndsWith(".doc") = True Then

reFileType.IsValid = True

End If

Catch ex As Exception

reFileType.IsValid = False

End Try

End Function

"Glavich, Paul C" <Click here to reveal e-mail address> wrote:

The regex validator should work, try fiddling with the regex expression. I
personally hate these and am not good at them so wont even try coming up
with a good regex expression. Alternatively, in your code, you could check
the extension with

If
String.Compare(uplFile.Value.Substring(uplFile.Value.Substring.length-4,4),"
.doc") = true then...

* Paul Glavich
Professional Web Services
Email: Click here to reveal e-mail address
Urgent Messages: Email Click here to reveal e-mail address and place urgent in subject line.
(Currently no fixed phone or street address)

-----Original Message-----
From: Wes Loukota [mailto:Click here to reveal e-mail address]
Sent: Monday, 15 July 2002 11:01 PM
To: aspng-validators
Subject: [aspng-validators] Custom Validator

-- Moved from [aspngfreeforall] to [aspng-validators] by Tim Musschoot
--

--! 0-697297990-1026738054=:46284
Content-Type: text/plain; charset=us-ascii

Hi all,

I am try to trying restrict upload to only .doc files. I have looked through
the documentation and was really confused by the syntax. I attempted to use
a regular expression validator but it doesn't seem to allow custom regex,
unless I don't have the proper syntax. Below is the code for the custom
validator I am trying to use. I've set the sub below as a break point and
tried stepping through the debugger (in VS.Net ver 7.0.9466), but it
doesn't break at that point and the validator summary message box pops up
declaring "The only acceptable files for upload are .doc files !" which is
the error message I set.

Any suggestions on how to fix this or where to look would be appreciated.

Thanks,

Wes

Sub FileValidation(ByVal source As Object, ByVal args As
ServerValidateEventArgs)

Try

If uplFile.Value = "(\w,\W)*\! .\d\o\c" Then

args.IsValid = True

End If

Catch ex As Exception

args.IsValid = False

End Try

End Sub

---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes --0-697297990-1026738054=:46284
Content-Type: text/html; charset=us-ascii

Hi all,

I am try to trying restrict upload to only .doc files. I have looked
through the documentation and was really confused by the syntax. I attempted
to use a regular expression validator but it doesn't seem to allow
custom regex, unless I don't have the proper syntax. Below is the code for
the custom validator I am trying to use. I've set the sub below as a break
point and tried stepping through the debugger (in VS.Net ver
7.0.9466), but it doesn't break at that point and the validator summary
message box pops up declaring "The only acceptable files for upload are .doc
files !" which is the error message I set.

Any suggestions on how to
fix this or where to look would be appreciated.

Thanks,

Wes

Sub
size=2> FileValidation(ByVal
size=2> source As
Object,
color=#0000ff size=2>ByVal args
color=#0000ff size=2>As ServerValidateEventArgs)

Try

If uplFile.Value "(\w,\W)*\.\d\o\c" Then

size=2>

args.IsValid = size=2>True

size=2>End size=2>If

size=2>Catch ex size=2>As Exception

args.IsValid =
color=#0000ff size=2>False

color=#0000ff size=2>End size=2>Try

size=2>End size=2>Sub

_____

Do You Yahoo!?

href="http://autos.yahoo.com/">Yahoo! Autos - Get free new car price
quotes
--0-697297990-1026738054=:46284--
| [aspng-validators] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspng-validators.asp" target="_blank">http://www.aspfriends.com/aspfriends/aspng-validators.asp = JOIN/QUIT

| [aspng-validators] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspng-validators.asp" target="_blank">http://www.aspfriends.com/aspfriends/aspng-validators.asp = JOIN/QUIT

Be sure to visit The Top Dog at http://the72bulldogs.com
<http://the72bulldogs.com> <http://the72bulldogs.com>

_____

Do You Yahoo!?
New! SBC Yahoo! Dial
<http://pa.yahoo.com/" target="_blank">http://pa.yahoo.com/*http://rd.yahoo.com/sbcyahoo/consumer/evt=640/" target="_blank">http://rd.yahoo.com/sbcyahoo/consumer/evt=640/*http://
sbc.yahoo.com> - 1st Month Free & unlimited access
Reply to this message...
 
 
System.String
System.Web.UI.MobileControls.CustomValidator
System.Web.UI.WebControls.ServerValidateEventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification