FileUpload clears on Insert

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
<Insert> 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?
TDisPSP [ So, 20 April 2008 22:58 ] [ ID #1946200 ]

Re: FileUpload clears on Insert

On Apr 20, 10:58=A0pm, TD is PSP <TDis... [at] discussions.microsoft.com>
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
> <Insert> 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.
lexa [ So, 20 April 2008 23:40 ] [ ID #1946202 ]

Re: FileUpload clears on Insert

> 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:

<% [at] Page Language="C#" MasterPageFile="~/EMFT.Master" AutoEventWireup="true"
CodeBehind="PublicUpload.aspx.cs" Inherits="EMailFileTransfer.PublicUpload"
Title="EMail File Transfer - Public Upload" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<asp:ScriptManager ID="smUpload" runat="server"/>
<asp:UpdateProgress ID="uprUpload" runat="server"
AssociatedUpdatePanelID="upUpload">
<ProgressTemplate>
File transfer in Progress . . .
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="upUpload" runat="server">
<ContentTemplate>
<table>
</table>
<asp:FormView id="fvTFiles" runat="server"
DataSourceID="dsTFiles" DataKeyNames="biID" DefaultMode="Insert">
<InsertItemTemplate>
<table cellpadding="5">
<tr>
<td>From</td>
<td><asp:TextBox ID="tbFrom" runat="server"
Width="300px"></asp:TextBox></td>
</tr>
<tr>
<td>From EMail (also for confirmation email)</td>
<td><asp:TextBox ID="tbFromEMail" runat="server"
Width="300px"></asp:TextBox></td>
</tr>
<tr>
<td>Send To</td>
<td><asp:DropDownList id="dlSendTo"
runat="server" Width="300px" DataTextField="sName" DataSourceID="dsTUsers"
DataValueField="sUserName" /></td>
</tr>
<tr>
<td>File Title</td>
<td><asp:TextBox id="sFileTitleTextBox"
runat="server" Text='<%# Bind("sFileTitle") %>'></asp:TextBox></td>
</tr>
<tr>
<td>Select File

<asp:RequiredFieldValidator ID="rfvUpload"
runat="server" ControlToValidate="fuUpload"

ErrorMessage="RequiredFieldValidator">You must select a file to
upload.</asp:RequiredFieldValidator></td>
<td><asp:FileUpload id="fuUpload" runat="server"
Width="661px"></asp:FileUpload></td>
</tr>
<tr>
<td><asp:Button id="bUpload" runat="server"
Text="Upload" CausesValidation="true" CommandName="Insert"
OnClick="bUpload_Click"></asp:Button></td>
<td>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource id="dsTFiles" runat="server"
ConnectionString="<%$ ConnectionStrings:EMailFileTransferConnectionString %>"
SelectCommandType="StoredProcedure" SelectCommand="spTFilesSelectByUserName"
InsertCommandType="StoredProcedure"
InsertCommand="spTFilesInsertWithUserName" OnInserting="dsTFiles_Inserting"
OnInserted="dsTFiles_Inserted">
<SelectParameters>
<asp:Parameter Type="String" Name="sUserName"
DefaultValue="" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Type="Int64" Direction="InputOutput"
Name="biID"></asp:Parameter>
<asp:Parameter Type="String" Name="sUserName"/>
<asp:Parameter Type="String"
Name="sFileTitle"></asp:Parameter>
<asp:Parameter Type="String"
Name="sFileName"></asp:Parameter>
<asp:Parameter Type="DateTime"
Name="dExpirationDateTime"></asp:Parameter>
<asp:Parameter Type="String" Direction="InputOutput"
Name="sUserEMail"></asp:Parameter>
<asp:Parameter Type="String" Direction="InputOutput"
Name="sPassword"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource> <asp:SqlDataSource id="dsTUsers"
runat="server" ConnectionString="<%$
ConnectionStrings:EMailFileTransferConnectionString %>"
SelectCommandType="StoredProcedure"
SelectCommand="spTUsersSelect"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
TDisPSP [ So, 20 April 2008 23:55 ] [ ID #1946205 ]

Re: FileUpload clears on Insert

On Apr 20, 11:55=A0pm, TD is PSP <TDis... [at] discussions.microsoft.com>
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:
>
> <% [at] 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" %>
> <asp:Content ID=3D"Content1" ContentPlaceHolderID=3D"ContentPlaceHolder1"
> runat=3D"server">
> =A0 =A0 <asp:ScriptManager ID=3D"smUpload" runat=3D"server"/>
> =A0 =A0 <asp:UpdateProgress ID=3D"uprUpload" runat=3D"server"
> AssociatedUpdatePanelID=3D"upUpload">
> =A0 =A0 =A0 =A0 <ProgressTemplate>
> =A0 =A0 =A0 =A0 =A0 =A0 File transfer in Progress . . .
> =A0 =A0 =A0 =A0 </ProgressTemplate>
> =A0 =A0 </asp:UpdateProgress>
> =A0 =A0 <asp:UpdatePanel ID=3D"upUpload" runat=3D"server">
> =A0 =A0 =A0 =A0 <ContentTemplate>
> =A0 =A0 =A0 =A0 =A0 =A0 <table>
> =A0 =A0 =A0 =A0 =A0 =A0 </table>
> =A0 =A0 =A0 =A0 =A0 =A0 <asp:FormView id=3D"fvTFiles" runat=3D"server"
> DataSourceID=3D"dsTFiles" DataKeyNames=3D"biID" DefaultMode=3D"Insert">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <InsertItemTemplate>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <table cellpadding=3D"5">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>From</td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:TextBox I=
D=3D"tbFrom" runat=3D"server"
> Width=3D"300px"></asp:TextBox></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>From EMail (al=
so for confirmation email)</td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:TextBox I=
D=3D"tbFromEMail" runat=3D"server"
> Width=3D"300px"></asp:TextBox></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>Send To</td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:DropDownL=
ist id=3D"dlSendTo"
> runat=3D"server" Width=3D"300px" DataTextField=3D"sName" DataSourceID=3D"d=
sTUsers"
> DataValueField=3D"sUserName" /></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>File Title</td=
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:TextBox i=
d=3D"sFileTitleTextBox"
> runat=3D"server" Text=3D'<%# Bind("sFileTitle") %>'></asp:TextBox></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>Select File<br=
/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Requi=
redFieldValidator ID=3D"rfvUpload"
> runat=3D"server" ControlToValidate=3D"fuUpload"
>
> ErrorMessage=3D"RequiredFieldValidator">You must select a file to
> upload.</asp:RequiredFieldValidator></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:FileUploa=
d id=3D"fuUpload" runat=3D"server"
> Width=3D"661px"></asp:FileUpload></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td><asp:Button id=
=3D"bUpload" runat=3D"server"
> Text=3D"Upload" CausesValidation=3D"true" CommandName=3D"Insert"
> OnClick=3D"bUpload_Click"></asp:Button></td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </td>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </tr>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </table>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </InsertItemTemplate>
> =A0 =A0 =A0 =A0 =A0 =A0 </asp:FormView> =A0
> =A0 =A0 =A0 =A0 =A0 =A0 <asp:SqlDataSource id=3D"dsTFiles" runat=3D"server=
"
> 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 <SelectParameters>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String" Nam=
e=3D"sUserName"
> DefaultValue=3D"" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </SelectParameters>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <InsertParameters>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"Int64" Dire=
ction=3D"InputOutput"
> Name=3D"biID"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String" Nam=
e=3D"sUserName"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String"
> Name=3D"sFileTitle"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String"
> Name=3D"sFileName"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"DateTime"
> Name=3D"dExpirationDateTime"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String" Dir=
ection=3D"InputOutput"
> Name=3D"sUserEMail"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <asp:Parameter Type=3D"String" Dir=
ection=3D"InputOutput"
> Name=3D"sPassword"></asp:Parameter>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </InsertParameters>
> =A0 =A0 =A0 =A0 =A0 =A0 </asp:SqlDataSource> <asp:SqlDataSource id=3D"dsTU=
sers"
> runat=3D"server" ConnectionString=3D"<%$
> ConnectionStrings:EMailFileTransferConnectionString %>"
> SelectCommandType=3D"StoredProcedure"
> SelectCommand=3D"spTUsersSelect"></asp:SqlDataSource>
> =A0 =A0 =A0 =A0 </ContentTemplate>
> =A0 =A0 </asp:UpdatePanel>
> </asp:Content>

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.
lexa [ Mo, 21 April 2008 08:49 ] [ ID #1946558 ]

Re: FileUpload clears on Insert

On Apr 20, 11:58 pm, TD is PSP <TDis... [at] discussions.microsoft.com>
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
> <Insert> 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
marss [ Mo, 21 April 2008 09:52 ] [ ID #1946561 ]

Re: FileUpload clears on Insert

On Apr 21, 9:52=A0am, marss <marss... [at] gmail.com> 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.
lexa [ Mo, 21 April 2008 11:52 ] [ ID #1946574 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » FileUpload clears on Insert

Vorheriges Thema: directory listing
Nächstes Thema: Sharing code between Projects.