Avatar of mainrotor
mainrotor

asked on 

I need help with a RequiredFieldValidator control in ASP.net 3.5

Hi Experts,
I need assistance using a RequiredFieldValidator control in my ASP.Net 3.5 application.  Currently the RequiredFieldValidator is checking to see if the file selected in my FileUpload control contains the words 'Year', and 'Report' in it (see attached code).  

I want the RequiredFieldValidator to make sure (validate) that the file selected in my FileUpload control also contains my DropDownList control's text value (DropDownList.SelectedItem.Text).  How can I do this?

Thanks in advance,
mrotor


<asp:RegularExpressionValidator 
ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Incorrect PSBD12 File."
ControlToValidate="fulPriorYearRSBD12"
ValidationExpression="^(?=.*?Year)(?=.*?PSBD12).*$" Font-Names="Arial" Font-Size="X-Small"/>

Open in new window

ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
mainrotor
Avatar of dejaanbu
dejaanbu
Flag of Oman image

you to have to add a custom validator ..in client function u should check the equality
Avatar of mainrotor
mainrotor

ASKER

How would I use the CustomValidator deejanbu?  Can you provide an Example?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Using the custom validator control

http://www.4guysfromrolla.com/articles/073102-1.aspx
ASKER CERTIFIED SOLUTION
Avatar of baiju_nagori
baiju_nagori
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dejaanbu
dejaanbu
Flag of Oman image

try @baiju_nagori's code and let us know
Avatar of mainrotor
mainrotor

ASKER

baiju
I get the following error when I try your code:

'ClientID' is not a member of 'System.Web.UI.WebControls.DropDownList'.      

I don't know if this has to do with the fact that I am creating my ddl at runtime and not at designtime like this:

ddl.DataValueField = "ClientID"
ddl.DataTextField = "ClientCode"
ddl.DataSource = GetData()



Also in your code, will the following line of code:
var fileName = filePath.substring(filePath.lastIndexOf('\\') + 1);

be affected if my file paths look like this:
C:\TestSpreadSheet\AnnualRGBReport.xls


Is the line of code expecting the double backslash in the filepath?  ('\\')


Thanks,
mrotor
Avatar of baiju_nagori
baiju_nagori
Flag of United States of America image

Can you post entire code along with ASPX?
Avatar of mainrotor
mainrotor

ASKER

Okay, will do.
Avatar of mainrotor
mainrotor

ASKER

Baiju, I figured it out.  Here is what I did.  I added the code below to my FileUpload Control source:
                <asp:CustomValidator ID="CustomValidator1" runat="server"
                    ControlToValidate="FileUpload1"
                    ErrorMessage="Incorrect file format."
                    OnServerValidate ="CheckYearValidation">*</asp:CustomValidator>

Then I added a validation procedure in my codebehind:
    Public Sub CheckYearValidation(ByVal source As Object, ByVal args As ServerValidateEventArgs)
         args.IsValid = (args.Value.Contains("Year") _
                        And args.Value.Contains("PSBD12") _
                        And args.Value.Contains(ddlClient.SelectedItem.Text))
    End Sub

That worked.  Thanks baiju for your help.

mrotor


.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo