[Solved] FileUpload is empty after UpdatePanel Partial Postback in ASP.Net

Last Reply 4 months ago By pandeyism

Posted 4 months ago

I have used update panel in that after click on dropdown list file uploader attachment removed. Need to avoid remove file uploader attachement. Below is the my code. please suggest any solution.

<div class="form-horizontal">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

        <div class="form-group">
            <div class="col-md-12 col-lg-12">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">                       
                        <div class="x_content">
                            <div class="form-horizontal">
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                    <ContentTemplate>
                                        <div class="form-group">
                                            <asp:Label ID="lblDate" runat="server" Text="Date" CssClass="col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon"><span class="fa fa-calendar"></span></span>
                                                    <asp:TextBox ID="txtRquestRaisedDate" runat="server" CssClass="form-control form-control-sm disabled" Enabled="false"></asp:TextBox>
                                                    <asp:CalendarExtender ID="Cal_RequestDate" runat="server" TargetControlID="txtRquestRaisedDate"></asp:CalendarExtender>
                                                </div>
                                            </div>

                                            <asp:Label ID="Label6" runat="server" Text="Department" CssClass=" col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <asp:DropDownList ID="drpDepartment" runat="server" class="selectpicker" AutoPostBack="true" data-live-search-style="begin" data-live-search="true"></asp:DropDownList>
                                            </div>

                                            <asp:Label ID="lblComplience" runat="server" Text="Complience Type" CssClass=" col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <asp:DropDownList ID="drpComplience" runat="server" class="selectpicker" AutoPostBack="true" data-live-search-style="begin" data-live-search="true"></asp:DropDownList>
                                            </div>


                                        </div>

                                        <div class="form-group">
                                            <asp:Label ID="Label3" runat="server" Text="Application" CssClass=" col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <asp:DropDownList ID="drpApplication" runat="server" class="selectpicker" AutoPostBack="true" data-live-search-style="begin" data-live-search="true"></asp:DropDownList>
                                            </div>


                                            <asp:Label ID="Label5" runat="server" Text="Request Type" CssClass="col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <asp:DropDownList ID="drpRequest_Type" runat="server" class="selectpicker" AutoPostBack="true" data-live-search-style="begin" data-live-search="true"></asp:DropDownList>
                                            </div>
                                            
                                            <asp:Label ID="lblFileUpload" runat="server" Text="Status" Visible="false" CssClass=" col-md-1 col-lg-1 control-label" Font-Size="small" Font-Bold="true"></asp:Label>
                                            <div class="col-lg-3 col-md-3">
                                                <asp:FileUpload ID="FileupAttache" runat="server" AllowMultiple="true" CssClass="form-control-sm" />
                                            </div>


                                        </div>
                                    </ContentTemplate>                                  
                                   
                                </asp:UpdatePanel>

                                <div class="form-group">
                                    <%--<script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>--%>
                                    <script src="js/tinymce.min.js"></script>
                                    
                                    <script type="text/javascript">
                                        tinymce.init({ selector: 'textarea', height: 200 });

                                    </script>

                                    <div class="col-md-12 col-lg-12">
                                        <asp:Label ID="Label8" Text="Enter Issue details in below textbox" runat="server" CssClass="control-label" Font-Bold="true" />
                                    </div>
                                    <div class="col-md-12 col-lg-12">
                                        <asp:TextBox ID="txtIssueDesc" runat="server" TextMode="MultiLine" CssClass="form-control" Placeholder="Issue" AutoPostBack="true" />
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-md-offset-3 col-lg-offset-3 col-lg-3 col-md-3">
                                        <asp:LinkButton ID="btnSave" Text="Save" runat="server" CssClass="btn btn-block btn-success btn-md" OnClick="btnSave_Click">                         <span class="fa fa fa-paper-plane-o"></span>&nbsp;Submit Request                             </asp:LinkButton>
                                    </div>
                                    <div class="col-lg-3 col-md-3">
                                        <asp:LinkButton ID="btnClear" Text="Clear" runat="server" CssClass="btn btn-block btn-md btn-success">                         <span class="fa fa-repeat"></span>&nbsp;Clear                             </asp:LinkButton>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

          
                </div>
            </div>
        </div>

       </div>

 

Posted 4 months ago Modified on 4 months ago

Hi Amol111,

Your html is inside updatepanel so when you select dropdown then fileupload also is getting refresh because of fileupload also inside updatepanel. If you did't want to refresh fileupload when dropdown value changed so you need to put fileupload outside the uploadpanel.

Refer below html.

HTML

<div class="form-horizontal">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div class="form-group">
        <div class="col-md-12 col-lg-12">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_content">
                        <div class="form-horizontal">
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                <ContentTemplate>
                                    <div class="form-group">
                                        <asp:Label ID="lblDate" runat="server" Text="Date" CssClass="col-md-1 col-lg-1 control-label"
                                            Font-Size="small" Font-Bold="true"></asp:Label>
                                        <div class="col-lg-3 col-md-3">
                                            <div class="input-group">
                                                <span class="input-group-addon"><span class="fa fa-calendar"></span></span>
                                                <asp:TextBox ID="txtRquestRaisedDate" runat="server" CssClass="form-control form-control-sm disabled"
                                                    Enabled="false"></asp:TextBox>
                                                <asp:CalendarExtender ID="Cal_RequestDate" runat="server" TargetControlID="txtRquestRaisedDate">
                                                </asp:CalendarExtender>
                                            </div>
                                        </div>
                                        <asp:Label ID="Label6" runat="server" Text="Department" CssClass=" col-md-1 col-lg-1 control-label"
                                            Font-Size="small" Font-Bold="true"></asp:Label>
                                        <div class="col-lg-3 col-md-3">
                                            <asp:DropDownList ID="drpDepartment" runat="server" class="selectpicker" AutoPostBack="true"
                                                data-live-search-style="begin" data-live-search="true">
                                            </asp:DropDownList>
                                        </div>
                                        <asp:Label ID="lblComplience" runat="server" Text="Complience Type" CssClass=" col-md-1 col-lg-1 control-label"
                                            Font-Size="small" Font-Bold="true"></asp:Label>
                                        <div class="col-lg-3 col-md-3">
                                            <asp:DropDownList ID="drpComplience" runat="server" class="selectpicker" AutoPostBack="true"
                                                data-live-search-style="begin" data-live-search="true">
                                            </asp:DropDownList>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <asp:Label ID="Label3" runat="server" Text="Application" CssClass=" col-md-1 col-lg-1 control-label"
                                            Font-Size="small" Font-Bold="true"></asp:Label>
                                        <div class="col-lg-3 col-md-3">
                                            <asp:DropDownList ID="drpApplication" runat="server" class="selectpicker" AutoPostBack="true"
                                                data-live-search-style="begin" data-live-search="true">
                                            </asp:DropDownList>
                                        </div>
                                        <asp:Label ID="Label5" runat="server" Text="Request Type" CssClass="col-md-1 col-lg-1 control-label"
                                            Font-Size="small" Font-Bold="true"></asp:Label>
                                        <div class="col-lg-3 col-md-3">
                                            <asp:DropDownList ID="drpRequest_Type" runat="server" class="selectpicker" AutoPostBack="true"
                                                data-live-search-style="begin" data-live-search="true">
                                                <asp:ListItem>1</asp:ListItem>
                                                <asp:ListItem>2</asp:ListItem>
                                                <asp:ListItem>3</asp:ListItem>
                                            </asp:DropDownList>
                                        </div>
                                    </div>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            <asp:Label ID="lblFileUpload" runat="server" Text="Status" Visible="false" CssClass=" col-md-1 col-lg-1 control-label"
                                Font-Size="small" Font-Bold="true"></asp:Label>
                            <div class="col-lg-3 col-md-3">
                                <asp:FileUpload ID="FileupAttache" runat="server" AllowMultiple="true" CssClass="form-control-sm" />
                            </div>
                            <div class="form-group">
                                <script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
                                <script src="js/tinymce.min.js"></script>
                                <script type="text/javascript">
                                    tinymce.init({ selector: 'textarea', height: 200 });
 
                                </script>
                                <div class="col-md-12 col-lg-12">
                                    <asp:Label ID="Label8" Text="Enter Issue details in below textbox" runat="server"
                                        CssClass="control-label" Font-Bold="true" />
                                </div>
                                <div class="col-md-12 col-lg-12">
                                    <asp:TextBox ID="txtIssueDesc" runat="server" TextMode="MultiLine" CssClass="form-control"
                                        Placeholder="Issue" AutoPostBack="true" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-3 col-lg-offset-3 col-lg-3 col-md-3">
                                    <asp:LinkButton ID="btnSave" Text="Save" runat="server" CssClass="btn btn-block btn-success btn-md">                         <span class="fa fa fa-paper-plane-o"></span>&nbsp;Submit Request                             </asp:LinkButton>
                                </div>
                                <div class="col-lg-3 col-md-3">
                                    <asp:LinkButton ID="btnClear" Text="Clear" runat="server" CssClass="btn btn-block btn-md btn-success">                         <span class="fa fa-repeat"></span>&nbsp;Clear                             </asp:LinkButton>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>