HtmlInputFile inside a Usercontrol does'nt work
-
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
-
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
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 sameid
? + Do you put the user control inside the server form element? -
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 sameid
? + Do you put the user control inside the server form element?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
-
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
-
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.
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 -
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! StephanStephan, + 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.