Solved

Looping through HTMLInputFiles

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now