Link to home
Start Free TrialLog in
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

Avatar of Deja Anbu
Deja Anbu
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?
ASKER CERTIFIED SOLUTION
Avatar of baiju_nagori
baiju_nagori
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try @baiju_nagori's code and let us know
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
Can you post entire code along with ASPX?
Okay, will do.
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