0

I have an ASP.net webpage hosting a form broken up into various update panels to improve the flow of the page. Without the tabs and update panels it would take the user a while to scroll all the way to the bottom.

I have various data tables that validate independently and their summaries show in the area I have designated for them. All of them fire when the full document is submitted to the server. All of this works as I expect it to.

However, I was asked to add File functionality to this page so i'm using an upload control, again, nested in it's own update panel (async trigger bound to button) When the Required validator correctly returns false and the error message shows, this works as intended.

The real issue here is that on a SUCCESSFUL validation (and postback) the ENTIRE page then attempts to re-validate and as such, all of the required fields register as false. This is the ONLY section of the page that displays this behaviour

Does anyone know, or can anyone suggest where I might find the information i'm clearly missing.

 <asp:UpdatePanel runat="server" ID="uPnlDocs" UpdateMode="Conditional"> 

        <Triggers>
            <asp:PostBackTrigger ControlID="btnUploadFile" />
        </Triggers>

        <ContentTemplate>

            <div id="DivDocs" runat="server" class="tab-pane" visible="false">

                <div class="panel panel-default">

                    <div class="panel-heading">

                        <asp:Label ID="Label1" runat="server">
                    <h3><u>Supporting Documents</u></h3 >
                            <h4>Please upload any documents you would like to attach to the currently selected DRD record. </h4>
                            <h5>Click the "Browse/Choose File" button to select a file, Then click "Upload File"</h5>

                        </asp:Label>

                    </div>
                    <br />

                    <div class="panel-body">
                        <!-- Controls go in here -->
                        <asp:FileUpload runat="server" ID="DrdFile" CssClass="col-sm-3" ViewStateMode="Enabled"   />
                        <asp:Button runat="server" CausesValidation="true" ValidationGroup="VGUpload" ID="btnUploadFile" Text="Upload File" CssClass="btn btn-success col-sm-2" OnClick="btnUploadFile_Click" />
                        <asp:RequiredFieldValidator runat="server" ID="RFV_Upload" ControlToValidate="DrdFile" Display="None" ValidationGroup="VGUpload" ErrorMessage="File not Selected" CssClass="validationError col-sm-6"></asp:RequiredFieldValidator>


                        <asp:Label runat="server" ID="lblUploadText" Text="Add a description to go with your file" CssClass="col-sm-12" AssociatedControlID="txtUploadFile" />
                        <asp:TextBox runat="server" ID="txtUploadFile" TextMode="MultiLine" Rows="4" CssClass="col-sm-10" />

                    </div>

                </div>

UPDATE --

Through further research and testing I found that ALL of my validators are being fired not just the required field validators

According to MSDN; https://msdn.microsoft.com/en-us/library/hh882339(v=vs.110).aspx

I should be able to stop the validation from firing when the form is submitted by either;

  1. Putting <@ PAGE validateRequest="false" %> in the page directive (tried)

  2. Adding the settings to the web.config file (also tried)

I'm running out of ideas at this point I hope someone has figured this out.

Philip Mather
  • 73
  • 2
  • 9

1 Answers1

0

The FileUpload control is not compatible with UpdatePanel. That could be the problem.

From the Microsoft Site:

Controls that Are Not Compatible with UpdatePanel Controls

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:

  • TreeView control under several conditions. One is when callbacks are enabled that are not part of an asynchronous postback. Another is when you set styles directly as control properties instead of implicitly styling the control by using a reference to CSS styles. Another is when the EnableClientScript property is false (the default is true). Another is if you change the value of the EnableClientScript property between asynchronous postbacks.

  • Menu control when you set styles directly as control properties instead of implicitly styling the control by using a reference to CSS styles. For more information, see Menu Control Overview.

  • FileUpload and HtmlInputFile controls when they are used to upload files as part of an asynchronous postback.

  • GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.

  • Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls whose contents have not been converted to editable templates.

  • The Substitution control.

  • Validation controls, which includes the BaseCompareValidator, BaseValidator, CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, and ValidationSummary control.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • Thank you for your response @VDWWD. I am aware that the FileUpload control doesn't work with Async postbacks. in the code the trigger is bound is a Full Postback, which is how It works. The problem is that after the postback and the successful file upload, all of my required field validators start firing for (i think) no reason – Philip Mather Sep 12 '16 at 11:51
  • Try to place all the FileUpload controls and the corresponding validators outside the UpdatePanel. What happens then? – VDWWD Sep 12 '16 at 13:13
  • if i take the update panels out then the section of the page i'm trying to fix no longer displays. – Philip Mather Sep 12 '16 at 14:05