Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get ID of fileupload control

Reply
Thread Tools

How to get ID of fileupload control

 
 
Ray
Guest
Posts: n/a
 
      05-06-2010
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
 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      05-07-2010
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).

--
Patrice


"Ray" <(E-Mail Removed)> a écrit dans le message de groupe de discussion :
Xns9D709FA32FBD2nospamnospamcom@207.46.248.16...
> 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



 
Reply With Quote
 
 
 
 
ray
Guest
Posts: n/a
 
      05-07-2010
In article <#(E-Mail Removed)>, "Patrice" says...
>
> 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
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      05-07-2010
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...

--
Patrice


"ray" <(E-Mail Removed)> a écrit dans le message de groupe de discussion :
http://www.velocityreviews.com/forums/(E-Mail Removed)...
> In article <#(E-Mail Removed)>, "Patrice" says...
>>
>> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Selecting a date with the Calendar control clears the FileUpload control Nathan Sokalski ASP .Net 1 01-11-2007 06:47 AM
Selecting a date with the Calendar control clears the FileUpload control Nathan Sokalski ASP .Net Web Controls 0 01-11-2007 05:13 AM
FileUpload Control & Image Control eamon ASP .Net Web Controls 2 08-04-2005 07:04 PM
ASP.NET 2.0 FileUpload control Uncle Ben ASP .Net 5 03-23-2005 06:42 PM



Advertisments