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
Solved

Looping through HTMLInputFiles

Posted on 2004-08-16
3
263 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
3 Comments
 

Accepted Solution

by:
jpatel18 earned 100 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

809 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