Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Looping through HTMLInputFiles

Posted on 2004-08-16
3
Medium Priority
?
280 Views
Last Modified: 2008-02-01
I have HTMLFileInput fields with runat="server" like so:

<INPUT id="file1" type="file" name="file" runat="server">
<INPUT id="file2" type="file" name="file" runat="server">
<INPUT id="file3" type="file" name="file" runat="server">
...etc....

When the button is pressed to save the form/upload the files, I have a pretty lengthy sub that each of these boxes needs to be passed to.  Is there a way to do this via a looping structure of some sort, instead of me having to call the function once for each file field?

I want to avoid doing this:

-------------------------------------------
DoSomethingToMyFile(file1)
DoSomethingToMyFile(file2)
DoSomethingToMyFile(file3)

Function DoSomethingToMyFile(myFile as HTMLInputFile)
End Function
-------------------------------------------

because the page will have up to 30-40 file fields.  I'd rather do something to this effect:

-------------------------------------------
For i as Integer = 1 to intNumFiles
     DoSomethingToMyFile("file" & i)
Next

Function DoSomethingToMyFile(myFile as HTMLInputFile)
End Function
-------------------------------------------

You used to be able to do this in vbscript with the "Eval" statement - but I know that doesn't really apply in .NET.  Any ideas?

Thanks,
Clay
0
Comment
Question by:claygarrett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
jpatel18 earned 400 total points
ID: 11815329
You could loop through all controls like so:
       

        Dim objForm As HtmlForm
        Dim objControl As Control
        Dim objCheckBox As CheckBoxList
        Dim objDDL As DropDownList
        Dim objItem As ListItem


        objForm = CType(Page.FindControl("form1"), HtmlForm)

        For Each objControl In objForm.Controls

            Select Case objControl.GetType.ToString
                Case "System.Web.UI.WebControls.CheckBoxList"
                    objCheckBox = CType(objControl, CheckBoxList)

                    For Each objItem In objCheckBox.Items
                        If objItem.Selected = True Then
                            If objHomeSelections.fnSelectedOption(objItem.Value, Request.QueryString("strHomeSelection"), objCustomer.CustomerID, intModelID) = False Then
                                dblOptionsPrice = dblOptionsPrice + CDbl(objHomeSelections.fnGetCostOfOption(objItem.Value, intModelID))
                            End If
                        Else
                            If objHomeSelections.fnSelectedOption(objItem.Value, Request.QueryString("strHomeSelection"), objCustomer.CustomerID, intModelID) = True Then
                                dblOptionsPrice = dblOptionsPrice - CDbl(objHomeSelections.fnGetCostOfOption(objItem.Value, intModelID))
                            End If
                        End If

                    Next

                Case "System.Web.UI.WebControls.DropDownList"

                    objDDL = CType(objControl, DropDownList)

                    For Each objItem In objDDL.Items
                        If objItem.Selected = True Then
                            If objItem.Value <> "-----------------" Then
                                If objItem.Value <> "please select one" Then
                                    If objHomeSelections.fnSelectedOption(objItem.Value, Request.QueryString("strHomeSelection"), objCustomer.CustomerID, intModelID) = False Then
                                        dblOptionsPrice = dblOptionsPrice + CDbl(objHomeSelections.fnGetCostOfOption(objItem.Value, intModelID))
                                    End If
                                Else
                                    If objHomeSelections.fnSelectedOption(objItem.Value, Request.QueryString("strHomeSelection"), objCustomer.CustomerID, intModelID) = True Then
                                        dblOptionsPrice = dblOptionsPrice - CDbl(objHomeSelections.fnGetCostOfOption(objItem.Value, intModelID))
                                    End If
                                End If
                            End If
                        End If


                    Next

            End Select

        Next
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question