locked
Asp.net File Upload Postback Auto Uploading Problem RRS feed

  • Question

  • User-47589850 posted

    Hi all,

    I have a diffrent problem. I have 2 button, 1 file upload control and many textboxes. 

    btnsave save only textboxes text. another button only  if file upload has file triggered. 

    But if file upload select file and no btnimage click another button btnsave click as postback and auto file uploading to server but of course it does not save, but still pretends to upload it on the page.  Loading text appears  at the bottom left.

    This problem maybe html or asp.net.  Does anyone have an idea?

      <div class="form-group">
                                                    <label class="col-md-2 control-label">Status</label>
                                                    <div class="col-md-10">
                                                        <asp:TextBox ID="txtstatus" TextMode="MultiLine" Height="150" runat="server" CssClass="form-control"></asp:TextBox>
                                                    </div>
                                                </div> 
    
    
    <div class="col-md-12 text-center">
                                                <asp:Button ID="btnsave" runat="server" UseSubmitBehavior="false" OnClientClick="if (CheckForm()!=false){this.disabled=true; this.value='Please Wait...';} else{return false};" Text="Save" OnClick="btsave_Click" CssClass="btn btn-primary" />
                                            </div>
    
    
     <div class="col-md-10 m-b-10">
    
                                                        <div class="col-md-3">
                                                            <div class="fileupload btn btn-purple  waves-effect waves-light">
                                                                <span><i class="ion-upload m-r-5"></i>Select a File</span>
                                                                <asp:FileUpload ClientIDMode="Static"   ID="FileUpload1" accept="image/*" runat="server" CssClass="upload" />
                                                            </div>
    
                                                        </div>
                                                       
                                                        <div class="col-md-5">
                                                            <asp:Button ID="btnimage" runat="server" ClientIDMode="Static" Text="Image Upload" CssClass="btn btn-default" OnClick="btnimage_Click" />
                                                        	
                                                        </div>
    
                                                    </div>

    Saturday, August 29, 2020 11:45 AM

All replies

  • User475983607 posted

    There is one main form in ASP.NET Web Forms.   Both asp buttons will submit all the inputs and the file upload.  

    Saturday, August 29, 2020 3:04 PM
  • User-47589850 posted

    Hmm, as if everywhere there is a voice saying switch to mvc  :) 

    I use the master page and because one form tag. 

    I tried to check this with javascript. It works relatively well. 

    But Even if I cancel without selecting the file cancel the upload dialog window, it still makes me wait while saving.


    OnClientClick="if (CheckForm()!=false){this.disabled=true; this.value='Please Wait...';} else{return false};"

    <script type="text/javascript">
    function CheckForm() {
    var fil = document.getElementById("<%=FileUpload1.ClientID %>");
    fil.value = "";
    }

    Saturday, August 29, 2020 3:48 PM
  • User-939850651 posted

    Hi asp.netlearning,

    I think the problem you are facing now is that the postback of the page will cause the status of the file upload to change.

    This is inevitable, it is caused by asp.net design. You can save the files in the upload control in other ways, such as session.

    Please refer to the solution in the case below:

    How to postback a page without the fileupload control losing the file attached ?

    If I misunderstood something, please feel free let me know.

    Best regards,

    Xudong Peng

    Monday, August 31, 2020 9:27 AM