FileUpload clears on Insert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VEQgaXMgUFNQ?=

    #1

    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?
  • Alexey Smirnov

    #2
    Re: FileUpload clears on Insert

    On Apr 20, 10:58 pm, TD is PSP <TDis...@discus sions.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.

    Comment

    • =?Utf-8?B?VEQgaXMgUFNQ?=

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

      <%@ Page Language="C#" MasterPageFile= "~/EMFT.Master" AutoEventWireup ="true"
      CodeBehind="Pub licUpload.aspx. cs" Inherits="EMail FileTransfer.Pu blicUpload"
      Title="EMail File Transfer - Public Upload" %>
      <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
      runat="server">
      <asp:ScriptMana ger ID="smUpload" runat="server"/>
      <asp:UpdateProg ress ID="uprUpload" runat="server"
      AssociatedUpdat ePanelID="upUpl oad">
      <ProgressTempla te>
      File transfer in Progress . . .
      </ProgressTemplat e>
      </asp:UpdateProgr ess>
      <asp:UpdatePane l ID="upUpload" runat="server">
      <ContentTemplat e>
      <table>
      </table>
      <asp:FormView id="fvTFiles" runat="server"
      DataSourceID="d sTFiles" DataKeyNames="b iID" DefaultMode="In sert">
      <InsertItemTemp late>
      <table cellpadding="5" >
      <tr>
      <td>From</td>
      <td><asp:TextBo x ID="tbFrom" runat="server"
      Width="300px"></asp:TextBox></td>
      </tr>
      <tr>
      <td>From EMail (also for confirmation email)</td>
      <td><asp:TextBo x ID="tbFromEMail " runat="server"
      Width="300px"></asp:TextBox></td>
      </tr>
      <tr>
      <td>Send To</td>
      <td><asp:DropDo wnList id="dlSendTo"
      runat="server" Width="300px" DataTextField=" sName" DataSourceID="d sTUsers"
      DataValueField= "sUserName" /></td>
      </tr>
      <tr>
      <td>File Title</td>
      <td><asp:TextBo x id="sFileTitleT extBox"
      runat="server" Text='<%# Bind("sFileTitl e") %>'></asp:TextBox></td>
      </tr>
      <tr>
      <td>Select File<br />
      <asp:RequiredFi eldValidator ID="rfvUpload"
      runat="server" ControlToValida te="fuUpload"

      ErrorMessage="R equiredFieldVal idator">You must select a file to
      upload.</asp:RequiredFie ldValidator></td>
      <td><asp:FileUp load id="fuUpload" runat="server"
      Width="661px"></asp:FileUpload> </td>
      </tr>
      <tr>
      <td><asp:Butt on id="bUpload" runat="server"
      Text="Upload" CausesValidatio n="true" CommandName="In sert"
      OnClick="bUploa d_Click"></asp:Button></td>
      <td>
      </td>
      </tr>
      </table>
      </InsertItemTempl ate>
      </asp:FormView>
      <asp:SqlDataSou rce id="dsTFiles" runat="server"
      ConnectionStrin g="<%$ ConnectionStrin gs:EMailFileTra nsferConnection String %>"
      SelectCommandTy pe="StoredProce dure" SelectCommand=" spTFilesSelectB yUserName"
      InsertCommandTy pe="StoredProce dure"
      InsertCommand=" spTFilesInsertW ithUserName" OnInserting="ds TFiles_Insertin g"
      OnInserted="dsT Files_Inserted" >
      <SelectParamete rs>
      <asp:Paramete r Type="String" Name="sUserName "
      DefaultValue="" />
      </SelectParameter s>
      <InsertParamete rs>
      <asp:Paramete r Type="Int64" Direction="Inpu tOutput"
      Name="biID"></asp:Parameter>
      <asp:Paramete r Type="String" Name="sUserName "/>
      <asp:Paramete r Type="String"
      Name="sFileTitl e"></asp:Parameter>
      <asp:Paramete r Type="String"
      Name="sFileName "></asp:Parameter>
      <asp:Paramete r Type="DateTime"
      Name="dExpirati onDateTime"></asp:Parameter>
      <asp:Paramete r Type="String" Direction="Inpu tOutput"
      Name="sUserEMai l"></asp:Parameter>
      <asp:Paramete r Type="String" Direction="Inpu tOutput"
      Name="sPassword "></asp:Parameter>
      </InsertParameter s>
      </asp:SqlDataSour ce<asp:SqlDataS ource id="dsTUsers"
      runat="server" ConnectionStrin g="<%$
      ConnectionStrin gs:EMailFileTra nsferConnection String %>"
      SelectCommandTy pe="StoredProce dure"
      SelectCommand=" spTUsersSelect" ></asp:SqlDataSour ce>
      </ContentTemplate >
      </asp:UpdatePanel >
      </asp:Content>

      Comment

      • Alexey Smirnov

        #4
        Re: FileUpload clears on Insert

        On Apr 20, 11:55 pm, TD is PSP <TDis...@discus sions.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="Pub licUpload.aspx. cs" Inherits="EMail FileTransfer.Pu blicUpload"
        Title="EMail File Transfer - Public Upload" %>
        <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
        runat="server">
            <asp:ScriptMana ger ID="smUpload" runat="server"/>
            <asp:UpdateProg ress ID="uprUpload" runat="server"
        AssociatedUpdat ePanelID="upUpl oad">
                <ProgressTempla te>
                    File transfer in Progress . . .
                </ProgressTemplat e>
            </asp:UpdateProgr ess>
            <asp:UpdatePane l ID="upUpload" runat="server">
                <ContentTemplat e>
                    <table>
                    </table>
                    <asp:FormView id="fvTFiles" runat="server"
        DataSourceID="d sTFiles" DataKeyNames="b iID" DefaultMode="In sert">
                        <InsertItemTemp late>
                            <table cellpadding="5" >
                                <tr>
                                    <td>From</td>
                                    <td><asp:TextBo x ID="tbFrom" runat="server"
        Width="300px"></asp:TextBox></td>
                                </tr>
                                <tr>
                                    <td>From EMail (also for confirmation email)</td>
                                    <td><asp:TextBo x ID="tbFromEMail " runat="server"
        Width="300px"></asp:TextBox></td>
                                </tr>
                                <tr>
                                    <td>Send To</td>
                                    <td><asp:DropDo wnList id="dlSendTo"
        runat="server" Width="300px" DataTextField=" sName" DataSourceID="d sTUsers"
        DataValueField= "sUserName" /></td>
                                </tr>
                                <tr>
                                    <td>File Title</td>
                                    <td><asp:TextBo x id="sFileTitleT extBox"
        runat="server" Text='<%# Bind("sFileTitl e") %>'></asp:TextBox></td>
                                </tr>
                                <tr>
                                    <td>Select File<br/>
                                        <asp:RequiredFi eldValidator ID="rfvUpload"
        runat="server" ControlToValida te="fuUpload"
        >
        ErrorMessage="R equiredFieldVal idator">You must select a file to
        upload.</asp:RequiredFie ldValidator></td>
                                    <td><asp:FileUp load id="fuUpload" runat="server"
        Width="661px"></asp:FileUpload> </td>
                                </tr>
                                <tr>
                                    <td><asp:Butt on id="bUpload" runat="server"
        Text="Upload" CausesValidatio n="true" CommandName="In sert"
        OnClick="bUploa d_Click"></asp:Button></td>
                                    <td>
                                        </td>
                                </tr>
                            </table>
                        </InsertItemTempl ate>
                    </asp:FormView 
                    <asp:SqlDataSou rce id="dsTFiles" runat="server"
        ConnectionStrin g="<%$ ConnectionStrin gs:EMailFileTra nsferConnection String %>"
        SelectCommandTy pe="StoredProce dure" SelectCommand=" spTFilesSelectB yUserName"
        InsertCommandTy pe="StoredProce dure"
        InsertCommand=" spTFilesInsertW ithUserName" OnInserting="ds TFiles_Insertin g"
        OnInserted="dsT Files_Inserted" >
                        <SelectParamete rs>
                            <asp:Paramete r Type="String" Name="sUserName "
        DefaultValue="" />
                        </SelectParameter s>
                        <InsertParamete rs>
                            <asp:Paramete r Type="Int64" Direction="Inpu tOutput"
        Name="biID"></asp:Parameter>
                            <asp:Paramete r Type="String" Name="sUserName "/>
                            <asp:Paramete r Type="String"
        Name="sFileTitl e"></asp:Parameter>
                            <asp:Paramete r Type="String"
        Name="sFileName "></asp:Parameter>
                            <asp:Paramete r Type="DateTime"
        Name="dExpirati onDateTime"></asp:Parameter>
                            <asp:Paramete r Type="String" Direction="Inpu tOutput"
        Name="sUserEMai l"></asp:Parameter>
                            <asp:Paramete r Type="String" Direction="Inpu tOutput"
        Name="sPassword "></asp:Parameter>
                        </InsertParameter s>
                    </asp:SqlDataSour ce<asp:SqlDataS ource id="dsTUsers"
        runat="server" ConnectionStrin g="<%$
        ConnectionStrin gs:EMailFileTra nsferConnection String %>"
        SelectCommandTy pe="StoredProce dure"
        SelectCommand=" spTUsersSelect" ></asp:SqlDataSour ce>
                </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.

        Comment

        • marss

          #5
          Re: FileUpload clears on Insert

          On Apr 20, 11:58 pm, TD is PSP <TDis...@discus sions.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.


          Regards,
          Mykola

          Comment

          • Alexey Smirnov

            #6
            Re: FileUpload clears on Insert

            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.

            Comment

            Working...