我有一个ASP页面,其中有一个文件上传器。此文件上传器具有一个必需的字段验证器。当我选择所需的文件进行上传时,文件将成功上传,并显示一个信息框,其中包含一条成功消息。
当我单击信息框上的“确定”以使其消失时,它将尝试再次验证整个页面,并且信息框不会消失。
我尝试将文件上传器上的CausesValidation属性设置为false,但是没有运气。我也尝试过AutoPostBack和IsPostBack。
aspx代码
<%@ Page Title="Excel File Content Upload" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master"
CodeBehind="ExcelFileContentUpload.aspx.vb" Inherits="Company.Applications.ProductionEngine.UI.ExcelFileContentUpload" %>
<%@ Register Src="~/GenericControls/UC_InformationMessageBox.ascx" TagName="InformationBox"
TagPrefix="uc" %><asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
<asp:Label ID="lblTitle" Text="Excel File Content Upload" runat="server" />
</h2>
<br />
<asp:FileUpload ID="fileUploader" runat="server" Width="400px"/>
<br />
<br />
Choose Year: <asp:DropDownList ID="ddlYear" runat="server"></asp:DropDownList>
Choose Month: <asp:DropDownList ID="ddlMonth" runat="server"></asp:DropDownList>
<br />
<br />
<asp:Button ID="btnDataUpload" runat="server" Text="Upload Data" CssClass="buttonBlue"
Visible="true" Width="115px"/>
<asp:UpdatePanel ID="MainContentUpdatePanel" runat="server">
<ContentTemplate>
<uc:InformationBox ID="InformationBox" runat="server" EnableViewState="true"/>
<asp:RequiredFieldValidator ID="rvfFileUploader" runat="server" ControlToValidate="fileUploader"
ErrorMessage="* Select an Excel file to upload" ForeColor="Red"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
页面加载
#Region "PAGE LOAD"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Load years and months into their respective dropdown lists
If Not Page.IsPostBack Then
Dim _currentYear As Integer = DateTime.Now.Year
Dim _previousYear As Integer = DateTime.Now.Year - 1
Dim _month = CultureInfo.CreateSpecificCulture("en").DateTimeFormat.MonthNames
For i As Integer = 0 To _month.Length - 1
ddlMonth.Items.Add(New ListItem(_month(i), i + 1).ToString())
Next
ddlYear.Items.Add(_currentYear)
ddlYear.Items.Add(_previousYear)
End If
End Sub
#End Region