这是我的代码
<table style="width: 100%;">
<tr>
<td style="width: 200px;">
Name
</td>
<td style="vertical-align: top;">
<div style="float: left;">
<asp:TextBox ID="txtName" runat="server" Width="500px" CssClass="text01" />
</div>
<div style="float: left; padding: 2px 0 0 5px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" CssClass="error01"
ErrorMessage="This field is required !" Display="Dynamic" ControlToValidate="txtName"></asp:RequiredFieldValidator>
</div>
</td>
</tr>
<tr>
<td style="width: 200px;">
Position
</td>
<td style="vertical-align: top;">
<div style="float: left;">
<asp:TextBox ID="txtPosition" runat="server" Width="500px" CssClass="text01" />
</div>
<div style="float: left; padding: 2px 0 0 5px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" CssClass="error01"
ErrorMessage="This field is required !" Display="Dynamic" ControlToValidate="txtPosition"></asp:RequiredFieldValidator>
</div>
</td>
</tr>
<tr>
<td>
Vietnamese Position
</td>
<td>
<div style="float: left;">
<asp:TextBox ID="txtPositionVN" runat="server" Width="500px" CssClass="text01" />
</div>
<div style="float: left; padding: 2px 0 0 5px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="error01"
ErrorMessage="This field is required !" Display="Dynamic" ControlToValidate="txtPositionVN"></asp:RequiredFieldValidator>
</div>
</td>
</tr>
<tr>
<td>
Order
</td>
<td>
<asp:DropDownList ID="ddlOrder" runat="server" Height="16px" Width="150px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 200px;">
Email
</td>
<td style="vertical-align: top;">
<div style="float: left;">
<asp:TextBox ID="txtEmail" runat="server" Width="500px" CssClass="text01" />
</div>
<div style="float: left; padding: 2px 0 0 5px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" CssClass="error01"
ErrorMessage="This field is required !" Display="Dynamic" ControlToValidate="txtEmail"></asp:RequiredFieldValidator>
</div>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" CssClass="text01" Display="Dynamic"
ErrorMessage="Input valid email address !"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="width: 200px;">
Mobile Phone Number
</td>
<td style="vertical-align: top;">
<div style="float: left;">
<asp:TextBox ID="txtPhone" runat="server" Width="500px" CssClass="text01" />
</div>
<div style="float: left; padding: 2px 0 0 5px;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" CssClass="error01"
ErrorMessage="This field is required !" Display="Dynamic" ControlToValidate="txtPhone"></asp:RequiredFieldValidator>
</div>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="txtPhone" CssClass="text01" Display="Dynamic"
ErrorMessage="Input valid mobile phone number !" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="width: 200px;vertical-align: top;">
Address
</td>
<td style="vertical-align: top;">
<div style="float: left;">
<asp:TextBox ID="txtAdd" runat="server" Width="500px" CssClass="text01" TextMode="MultiLine" Height="200px" />
</div>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
Image
</td>
<td valign="top">
<asp:FileUpload ID="fupImage" runat="server" CssClass="text01" Width="400px" />
<asp:Image ID="imgURL" runat="server" Width="100px" Height="100px" Visible="false" />
<asp:Label ID="lblMessageForfupImage" runat="server" ForeColor="Red" Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td />
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" CssClass="text01" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click"
CssClass="text01" Visible="False" />
<asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click"
CssClass="text01" CausesValidation="False" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click"
CssClass="text01" Height="22px" CausesValidation="False" />
</td>
</tr>
</table>
代码背后:
if (fupImage.PostedFile.FileName != "")
{
if (!Utitlties.Instance.CheckImageFileType(fupImage.PostedFile.FileName))
{
lblMessageForfupImage.Visible = true;
lblMessageForfupImage.Text = "Image file only accept *.jpg, *.png, *.bmp, *.gif Extensions !";
fupImage.Focus();
}
else
{
evt.ImageURL = Utils.Instance.SaveImage(fupImage.PostedFile.InputStream, fupImage.PostedFile.FileName, true);
UniqueDesign.Utilities.Utitlties.Instance.DeleteFile(imgURL.ImageUrl);
}
}
当我重新填充它时,它的HasFile属性总是返回false,并且
fupImage.PostedFile.ContentLength = -2但它仍然有文件名和文件类型。
这是我的web.config:
<?xml version="1.0"?>
Visual Studio中的Asp.Net配置选项。 可以在中找到完整的设置和注释列表 machine.config.comments通常位于 \的Windows \ Microsoft.Net \框架\其中Vx.x \配置 - &GT;
</appSettings>
<connectionStrings/>
<!--<location path="admin_ServicesPhotosManager.aspx">
<system.web>
<httpRuntime executionTimeout="3600" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>
</system.web>
</location>-->
<system.web>
<httpRuntime executionTimeout="3600"
maxRequestLength="40960"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="FileUploadLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=AF961ECE0B692DFB"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="GET" type="darrenjohnstone.net.FileUpload.UploadProgressHandler, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb" path="UploadProgress.ashx"/>
<add verb="GET" type="darrenjohnstone.net.FileUpload.SQLFileDownloadHandler, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb" path="DownloadFile.ashx"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="upload_module" type="darrenjohnstone.net.FileUpload.UploadModule, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824">
</requestLimits>
</requestFiltering>
</security>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<remove name="upload_module" />
<add name="upload_module" type="darrenjohnstone.net.FileUpload.UploadModule, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb" />
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UploadProgress" verb="GET" type="darrenjohnstone.net.FileUpload.UploadProgressHandler, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb" path="UploadProgress.ashx" />
<add name="FileDownload" verb="GET" type="darrenjohnstone.net.FileUpload.SQLFileDownloadHandler, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb" path="DownloadFile.ashx" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
答案 0 :(得分:1)
当我遇到这个问题时,我遇到了这个问题,并认为我发布了我的问题和解决方案。
确保您尝试上传的文件大于0字节。我尝试上传一些空白文本文件进行测试,每个文件都正确设置了FileName
属性,但HasFile
总是假的。向文件中添加一些文本会为其提供一些内容,并且文件能够成功上传。
答案 1 :(得分:0)
那么你的UpdatePanel究竟在哪里?您是否尝试提交更新面板内的表单,但是还有一个不是的文件上载控件?
我认为这也无效。
您可以使用FileUpload的AJAX控件工具包版本,或使用其他内容,例如作为jquery插件的Uploadify。