FileUpload clears on Insert
FileUpload clears on Insert
am 20.04.2008 22:58:01 von TDisPSP
I have a FileUpload control within a FormView (although I tried it outside
the FormView and got the same result) in the InsertTemplate. When the
button is clicked and the Insert Command is executed the FileUpload
is cleared of it's value and hence during Insert there is no file to
"insert". I even tried this with a separate button that was both inside and
outside the form view and not connected to the Insert Command, and still the
FileUpload get's cleared.
How can I either stop the value from being cleared or what should I do
differently to accomplish the same result?
Re: FileUpload clears on Insert
am 20.04.2008 23:40:31 von lexa
On Apr 20, 10:58=A0pm, TD is PSP
wrote:
> I have a FileUpload control within a FormView (although I tried it outside=
> the FormView and got the same result) in the InsertTemplate. =A0When the
> button is clicked and the Insert Command is executed the FileUplo=
ad
> is cleared of it's value and hence during Insert there is no file to
> "insert". =A0I even tried this with a separate button that was both inside=
and
> outside the form view and not connected to the Insert Command, and still t=
he
> FileUpload get's cleared.
>
> How can I either stop the value from being cleared or what should I do
> differently to accomplish the same result?
Your button causes a postback and the FileUpload Control lost its
value. To solve this, you could use the UpdatePanel and wrap that
around the controls that are causing the postback.
Re: FileUpload clears on Insert
am 20.04.2008 23:55:02 von TDisPSP
> Your button causes a postback and the FileUpload Control lost its
> value. To solve this, you could use the UpdatePanel and wrap that
> around the controls that are causing the postback.
>
Actually the FormView is already in an UpdatePanel. Here's the code:
<%@ Page Language="C#" MasterPageFile="~/EMFT.Master" AutoEventWireup="true"
CodeBehind="PublicUpload.aspx.cs" Inherits="EMailFileTransfer.PublicUpload"
Title="EMail File Transfer - Public Upload" %>
runat="server">
AssociatedUpdatePanelID="upUpload">
File transfer in Progress . . .
DataSourceID="dsTFiles" DataKeyNames="biID" DefaultMode="Insert">
From |
Width="300px"> |
From EMail (also for confirmation email) |
Width="300px"> |
Send To |
runat="server" Width="300px" DataTextField="sName" DataSourceID="dsTUsers"
DataValueField="sUserName" /> |
File Title |
runat="server" Text='<%# Bind("sFileTitle") %>'> |
Select File
runat="server" ControlToValidate="fuUpload"
ErrorMessage="RequiredFieldValidator">You must select a file to
upload. |
Width="661px"> |
Text="Upload" CausesValidation="true" CommandName="Insert"
OnClick="bUpload_Click"> |
|
ConnectionString="<%$ ConnectionStrings:EMailFileTransferConnectionString %>"
SelectCommandType="StoredProcedure" SelectCommand="spTFilesSelectByUserName"
InsertCommandType="StoredProcedure"
InsertCommand="spTFilesInsertWithUserName" OnInserting="dsTFiles_Inserting"
OnInserted="dsTFiles_Inserted">
DefaultValue="" />
Name="biID">
Name="sFileTitle">
Name="sFileName">
Name="dExpirationDateTime">
Name="sUserEMail">
Name="sPassword">
runat="server" ConnectionString="<%$
ConnectionStrings:EMailFileTransferConnectionString %>"
SelectCommandType="StoredProcedure"
SelectCommand="spTUsersSelect">
Re: FileUpload clears on Insert
am 21.04.2008 08:49:29 von lexa
On Apr 20, 11:55=A0pm, TD is PSP
wrote:
> > Your button causes a postback and the FileUpload Control lost its
> > value. To solve this, you could use the UpdatePanel and wrap that
> > around the controls that are causing the postback.
>
> Actually the FormView is already in an UpdatePanel. =A0Here's the code:
>
> <%@ Page Language=3D"C#" MasterPageFile=3D"~/EMFT.Master" AutoEventWireup=
=3D"true"
> CodeBehind=3D"PublicUpload.aspx.cs" Inherits=3D"EMailFileTransfer.PublicUp=
load"
> Title=3D"EMail File Transfer - Public Upload" %>
>
> runat=3D"server">
> =A0 =A0
> =A0 =A0
> AssociatedUpdatePanelID=3D"upUpload">
> =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 File transfer in Progress . . .
> =A0 =A0 =A0 =A0
> =A0 =A0
> =A0 =A0
> =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
> DataSourceID=3D"dsTFiles" DataKeyNames=3D"biID" DefaultMode=3D"Insert">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 From |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
D=3D"tbFrom" runat=3D"server"
> Width=3D"300px"> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 From EMail (al=
so for confirmation email) |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
D=3D"tbFromEMail" runat=3D"server"
> Width=3D"300px"> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Send To |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ist id=3D"dlSendTo"
> runat=3D"server" Width=3D"300px" DataTextField=3D"sName" DataSourceID=3D"d=
sTUsers"
> DataValueField=3D"sUserName" /> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 File Title |
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
d=3D"sFileTitleTextBox"
> runat=3D"server" Text=3D'<%# Bind("sFileTitle") %>'> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Select File
/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
redFieldValidator ID=3D"rfvUpload"
> runat=3D"server" ControlToValidate=3D"fuUpload"
>
> ErrorMessage=3D"RequiredFieldValidator">You must select a file to
> upload. |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
d id=3D"fuUpload" runat=3D"server"
> Width=3D"661px"> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=3D"bUpload" runat=3D"server"
> Text=3D"Upload" CausesValidation=3D"true" CommandName=3D"Insert"
> OnClick=3D"bUpload_Click"> |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
"
> ConnectionString=3D"<%$ ConnectionStrings:EMailFileTransferConnectionStrin=
g %>"
> SelectCommandType=3D"StoredProcedure" SelectCommand=3D"spTFilesSelectByUse=
rName"
> InsertCommandType=3D"StoredProcedure"
> InsertCommand=3D"spTFilesInsertWithUserName" OnInserting=3D"dsTFiles_Inser=
ting"
> OnInserted=3D"dsTFiles_Inserted">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
e=3D"sUserName"
> DefaultValue=3D"" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ction=3D"InputOutput"
> Name=3D"biID">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
e=3D"sUserName"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> Name=3D"sFileTitle">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> Name=3D"sFileName">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> Name=3D"dExpirationDateTime">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ection=3D"InputOutput"
> Name=3D"sUserEMail">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ection=3D"InputOutput"
> Name=3D"sPassword">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
sers"
> runat=3D"server" ConnectionString=3D"<%$
> ConnectionStrings:EMailFileTransferConnectionString %>"
> SelectCommandType=3D"StoredProcedure"
> SelectCommand=3D"spTUsersSelect">
> =A0 =A0 =A0 =A0
> =A0 =A0
>
The FileUpload Control must be out of the UpdatePanel, otherwise it
will be updated once button is clicked. Or, you have to perfom a file
upload when you click on the button.
Re: FileUpload clears on Insert
am 21.04.2008 09:52:16 von marss
On Apr 20, 11:58 pm, TD is PSP
wrote:
> I have a FileUpload control within a FormView (although I tried it outside
> the FormView and got the same result) in the InsertTemplate. When the
> button is clicked and the Insert Command is executed the FileUpload
> is cleared of it's value and hence during Insert there is no file to
> "insert". I even tried this with a separate button that was both inside and
> outside the form view and not connected to the Insert Command, and still the
> FileUpload get's cleared.
>
> How can I either stop the value from being cleared or what should I do
> differently to accomplish the same result?
Here are a few tips how to use FileUpload within UpdatePanel.
http://marss.co.ua/FileUploadAndUpdatePanel.aspx
Regards,
Mykola
Re: FileUpload clears on Insert
am 21.04.2008 11:52:44 von lexa
On Apr 21, 9:52=A0am, marss wrote:
> Here are a few tips how to use FileUpload within UpdatePanel.http://marss.=
co.ua/FileUploadAndUpdatePanel.aspx
>
> Regards,
> Mykola
I think, his problem is different. His FileUpload Control lost the
text value on a postback. It has nothing to do with an UpdatePanel
because it's a standard behavior of the FileUpload. It does not keep
the value after postback.