How to get ID of fileupload control

Discussion in 'ASP .Net' started by Ray, May 6, 2010.

  1. Ray

    Ray Guest

    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
    Ray, May 6, 2010
    #1
    1. Advertising

  2. Ray

    Patrice Guest

    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" <> 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
    Patrice, May 7, 2010
    #2
    1. Advertising

  3. Ray

    ray Guest

    In article <#>, "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
    ray, May 7, 2010
    #3
  4. Ray

    Patrice Guest

    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" <> a écrit dans le message de groupe de discussion :
    ...
    > In article <#>, "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
    Patrice, May 7, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Uncle Ben

    ASP.NET 2.0 FileUpload control

    Uncle Ben, Mar 23, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,781
    Bruce Barker
    Mar 23, 2005
  2. Eric

    FileUpload control.

    Eric, Dec 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    5,794
    Ankho
    Nov 3, 2009
  3. Nathan Sokalski
    Replies:
    1
    Views:
    743
    Mark Rae
    Jan 11, 2007
  4. eamon

    FileUpload Control & Image Control

    eamon, Aug 4, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    202
    eamon
    Aug 4, 2005
  5. Nathan Sokalski
    Replies:
    0
    Views:
    251
    Nathan Sokalski
    Jan 11, 2007
Loading...

Share This Page