How to get ID of fileupload control

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
 
P

Patrice

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).
 
R

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).

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
 
P

Patrice

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top