Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HtmlInputFile inside a Usercontrol does'nt work

HtmlInputFile inside a Usercontrol does'nt work

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Pilz
    wrote on last edited by
    #1

    Hello Friends, I have a HtmlInputFile-Object inside a Usercontrol. The Instances of this UserControl is dynamic generated in Code-Behind via a LoadControl-Call. My Problem is, after PostBack the Page, in Page_Load of the UserControl my server side variable of type HtmlInputFile has no value set and the property PostedFile is nothing too.:mad: In the Page, the form-tag have enctype="multipart/form-data" set. Thx for all help Stephan

    M 1 Reply Last reply
    0
    • S Stephan Pilz

      Hello Friends, I have a HtmlInputFile-Object inside a Usercontrol. The Instances of this UserControl is dynamic generated in Code-Behind via a LoadControl-Call. My Problem is, after PostBack the Page, in Page_Load of the UserControl my server side variable of type HtmlInputFile has no value set and the property PostedFile is nothing too.:mad: In the Page, the form-tag have enctype="multipart/form-data" set. Thx for all help Stephan

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, Just curious about a couple of things (I assume you add the input file to the user control at design time): + Does the input file element declared in the user control have runat="server"? + Do they (the input file declared in the user control and the variable used in code-behind) have the same id? + Do you put the user control inside the server form element?

      S 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, Just curious about a couple of things (I assume you add the input file to the user control at design time): + Does the input file element declared in the user control have runat="server"? + Do they (the input file declared in the user control and the variable used in code-behind) have the same id? + Do you put the user control inside the server form element?

        S Offline
        S Offline
        Stephan Pilz
        wrote on last edited by
        #3

        Thx for your answer, but: + The input element is declared as runat="server" + The input element have the same id like the class member + In a user control does'nt exist a form tag! The Form-Tag exist in the Page and the UC is embedded in the Form-Tag in the Page (incl. enctype-statement). Stephan

        M 1 Reply Last reply
        0
        • S Stephan Pilz

          Thx for your answer, but: + The input element is declared as runat="server" + The input element have the same id like the class member + In a user control does'nt exist a form tag! The Form-Tag exist in the Page and the UC is embedded in the Form-Tag in the Page (incl. enctype-statement). Stephan

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Stephan, Do you think posting a snippet of your sample code may help people figure out your problem? As I want to know more that you dynamically load the user control every time the page is loaded or just in some specific contexts.

          S 1 Reply Last reply
          0
          • M minhpc_bk

            Stephan, Do you think posting a snippet of your sample code may help people figure out your problem? As I want to know more that you dynamically load the user control every time the page is loaded or just in some specific contexts.

            S Offline
            S Offline
            Stephan Pilz
            wrote on last edited by
            #5

            Hello here comes some code snippets: The UC: <%@ Control Language="vb" AutoEventWireup="false" Codebehind="CFOFileUploaderUC.ascx.vb" Inherits="CFOFileUploaderUC" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> Snippet of code behind: Public Class CFOFileUploaderUC Inherits System.Web.UI.UserControl Protected WithEvents Uploader As System.Web.UI.HtmlControls.HtmlInputFile Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IsPostBack Then ' Uploader.PostedFile is always nothing here !!! ' Uploader.Value is always empty here !!! End If End Sub End Class the form-tag in the page:

            And last but not least the creation of the user control (embed in a table cell). It's important to understand, that this creation-routine is inside of an other UC, that represents a record. The "outer"-UC is created through a repeater-object. oCFOFileUploaderUC = CType(LoadControl("CFOFileUploaderUC.ascx"), CFOFileUploaderUC) ' Setting some properties here oCFOFileUploaderUC.table_name = m_DataView.Table.TableName oCFOFileUploaderUC.refid_name = "cfd_refid" oCFOFileUploaderUC.refid_value = 0 oCFOFileUploaderUC.attr_name = Trim(oRec.Item("ctp_fieldname")) ' adding to the table cell oTd.Controls.Add(oCFOFileUploaderUC) If I enter a file via file selection box and call submit() on Form1 via client side javascript, I step first trouhgt Page_Load from the Page class and after this Page_Load of the UC. Between this, I recreate the UC! Maybe this is the problem, but I don't know, how I can read the input from UC's input-file direct from the page class, because I hav'nt an class member for the UC (dyn. created). It's not possible, to change the code from dyn. UC to static, because some informations in the record determine, whether the input-file-object is needed. It's very tricky I know, but I hope, that helps to understand all! Stephan

            M 1 Reply Last reply
            0
            • S Stephan Pilz

              Hello here comes some code snippets: The UC: <%@ Control Language="vb" AutoEventWireup="false" Codebehind="CFOFileUploaderUC.ascx.vb" Inherits="CFOFileUploaderUC" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> Snippet of code behind: Public Class CFOFileUploaderUC Inherits System.Web.UI.UserControl Protected WithEvents Uploader As System.Web.UI.HtmlControls.HtmlInputFile Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IsPostBack Then ' Uploader.PostedFile is always nothing here !!! ' Uploader.Value is always empty here !!! End If End Sub End Class the form-tag in the page:

              And last but not least the creation of the user control (embed in a table cell). It's important to understand, that this creation-routine is inside of an other UC, that represents a record. The "outer"-UC is created through a repeater-object. oCFOFileUploaderUC = CType(LoadControl("CFOFileUploaderUC.ascx"), CFOFileUploaderUC) ' Setting some properties here oCFOFileUploaderUC.table_name = m_DataView.Table.TableName oCFOFileUploaderUC.refid_name = "cfd_refid" oCFOFileUploaderUC.refid_value = 0 oCFOFileUploaderUC.attr_name = Trim(oRec.Item("ctp_fieldname")) ' adding to the table cell oTd.Controls.Add(oCFOFileUploaderUC) If I enter a file via file selection box and call submit() on Form1 via client side javascript, I step first trouhgt Page_Load from the Page class and after this Page_Load of the UC. Between this, I recreate the UC! Maybe this is the problem, but I don't know, how I can read the input from UC's input-file direct from the page class, because I hav'nt an class member for the UC (dyn. created). It's not possible, to change the code from dyn. UC to static, because some informations in the record determine, whether the input-file-object is needed. It's very tricky I know, but I hope, that helps to understand all! Stephan

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Stephan, + Do you place the repeater control right in the web page? + In what method are you trying to add the outer UC to the repeater? Because, you basically need to add dynamic controls to the container at the right point of the page life cycle, then they can run properly. + You actually can access the file input of the UC in the code of the page class. You first expose the input file as a public property of the UC, then in the page class you can use the FindControl method to get a reference to the UC. Once you got it, you can freely get the uploaded data from the client side. + In fact, you are still able to use static controls here, depending on the current information of the row, you can make the UC of the row invisible or remove it out of the container.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups