How to get ID of fileupload control

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

Hi All,

I am having problem to get the ID of fileupload control in as loop:

<form enctype="multipart/form-data" method="post" runat="server">
<asp:FileUpLoad id="FileName1" runat="server" />
<asp:FileUpLoad id="FileName2" runat="server" />
<asp:FileUpLoad id="FileName3" runat="server" />
</form>

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
If Page.IsPostBack Then
Dim i As Integer
For i = 0 to Page.Controls.Count - 1
Response.Write(Page.Controls(i).ID & "<br>")
Next
Response.end()
End If
End Sub

this return empty, any help?

Thanks

Ray
 
Hello,

You should be able to access directly those fields using the FileName1,
FileName2,FileName3 variables created yor you...

For a better visibility put a breakpoint and/or print rather the type
(Page.Controls(i).GetType.ToString), you should have a control but as it has
non name...

The problem is likely that you are listed controls at the first level when
those controls are actually inside another control (declared by the form
tag).
 
Hello,

You should be able to access directly those fields using the FileName1,
FileName2,FileName3 variables created yor you...

For a better visibility put a breakpoint and/or print rather the type
(Page.Controls(i).GetType.ToString), you should have a control but as it has
non name...

The problem is likely that you are listed controls at the first level when
those controls are actually inside another control (declared by the form
tag).

Thank you Patrice,

But this is what I was look for:

Dim ctrl As Control
for each ctrl In Page.FindControl("form1").Controls
if ctrl.GetType() is GetType(FileUpload) then
Response.Write(ctrl.GetType.ToString & "<br>")
Response.Write(ctrl.ID.ToString & "<br>")
end if
next ctrl

Ray
 
This is not the code you posted...

Here try :
TypeOf ctrl is FileUpload

The difference is that you want to test if both types are the same actual
type not if those two object type are the same...

A quick sanity check would be to drop the test to make sure those controls
are listed...
 
Back
Top