Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Looping through HTMLInputFiles

Posted on 2004-08-16
3
Medium Priority
?
287 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

886 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