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
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
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"/>
you to have to add a custom validator ..in client function u should check the equality
ASKER
How would I use the CustomValidator deejanbu? Can you provide an Example?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try @baiju_nagori's code and let us know
ASKER
baiju
I get the following error when I try your code:
'ClientID' is not a member of 'System.Web.UI.WebControls .DropDownL ist'.
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(filePat h.lastInde xOf('\\') + 1);
be affected if my file paths look like this:
C:\TestSpreadSheet\AnnualR GBReport.x ls
Is the line of code expecting the double backslash in the filepath? ('\\')
Thanks,
mrotor
I get the following error when I try your code:
'ClientID' is not a member of 'System.Web.UI.WebControls
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(filePat
be affected if my file paths look like this:
C:\TestSpreadSheet\AnnualR
Is the line of code expecting the double backslash in the filepath? ('\\')
Thanks,
mrotor
Can you post entire code along with ASPX?
ASKER
Okay, will do.
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="FileUpl oad1"
ErrorMessage="Incorrect file format."
OnServerValidate ="CheckYearValidation">*</ asp:Custom Validator>
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("PSBD1 2") _
And args.Value.Contains(ddlCli ent.Select edItem.Tex t))
End Sub
That worked. Thanks baiju for your help.
mrotor
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="FileUpl
ErrorMessage="Incorrect file format."
OnServerValidate ="CheckYearValidation">*</
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("PSBD1
And args.Value.Contains(ddlCli
End Sub
That worked. Thanks baiju for your help.
mrotor