Solved

Looping through HTMLInputFiles

Posted on 2004-08-16
3
267 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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