473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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
<Insertbutton 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?
Jun 27 '08 #1
5 2749
On Apr 20, 10:58*pm, TD is PSP <TDis...@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
<Insertbutton 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 insideand
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?
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.
Jun 27 '08 #2
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:EMailFileTransferConnectionStrin g %>"
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:EMailFileTransferConnectionStrin g %>"
SelectCommandType="StoredProcedure"
SelectCommand="spTUsersSelect"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

Jun 27 '08 #3
On Apr 20, 11:55*pm, TD is PSP <TDis...@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. *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:EMailFileTransferConnectionStrin g %>"
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:EMailFileTransferConnectionStrin g %>"
SelectCommandType="StoredProcedure"
SelectCommand="spTUsersSelect"></asp:SqlDataSource>
* * * * </ContentTemplate>
* * </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.
Jun 27 '08 #4
On Apr 20, 11:58 pm, TD is PSP <TDis...@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
<Insertbutton 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
Jun 27 '08 #5
On Apr 21, 9:52*am, marss <marss...@gmail.comwrote:
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.
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: narmathabala | last post by:
Hello, I need to insert BLOB into MySQL DB from a C#.NET 2.0 environment. The piece of code which I am using is listed below. Note: fileup is a FileUpload holder <code> Stream content =...
1
by: Marko Vuksanovic | last post by:
I am trying to implement an upload progress indicator using atlas, using the following workaround: http://forums.asp.net/thread/1321664.aspx This is the code in FileUpload.apsx file is as...
0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
4
by: Dave | last post by:
If you had a FileUpload control inside of a FormView...how would you use FindControl to access the FileUpload properties? Let me just say that...
1
by: Nathan Sokalski | last post by:
I have an ASP.NET 2.0 webform which includes both a FileUpload contol and a Calendar control. When the user selects a new data with the Calendar control, the FileUpload control is reset (there is...
6
by: Chris | last post by:
I want do my insert to a database using a formview bound to an objectdatasource. I also want to upload a file. I'm quite new to and this is just test code but Is there any way I can pass the file...
0
by: =?Utf-8?B?Z292ZXI=?= | last post by:
Hello, I have a Formview in insert mode with a fileUpload control on it. I'm trying to get the contents of the uploaded file passed to my ObjectDataSource to be persisted to my database. The...
0
by: renatois | last post by:
FileUpload in DetailsView Hi guys, I have a FileUpload control as a insert template field in a DetailsView. How can I upload an image? Ty
0
by: pauld | last post by:
Hello- Note: this is all VB/Asp.net 2.0 I have a formview(insert template) whose fields are bound to a datagrid that is connects to an MS SQL Server 2005 database. One of the options on the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.