Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

FileUpload clears on Insert

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TD is PSP - 20 Apr 2008 21:58 GMT
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?
Alexey Smirnov - 20 Apr 2008 22:40 GMT
> 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
[quoted text clipped - 6 lines]
> 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.
TD is PSP - 20 Apr 2008 22:55 GMT
> 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" %>
<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<br />
                               <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>
Alexey Smirnov - 21 Apr 2008 07:49 GMT
> > Your button causes a postback and the FileUpload Control lost its
> > value. To solve this, you could use the UpdatePanel and wrap that
[quoted text clipped - 96 lines]
>     </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.
marss - 21 Apr 2008 08:52 GMT
> 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
[quoted text clipped - 6 lines]
> 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
Alexey Smirnov - 21 Apr 2008 10:52 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.