FileUpload.HasFile properties is not within UpdatePanel but still alway return false

Discussion in '.NET' started by Ne7ven, Apr 18, 2011.

  1. Ne7ven

    Ne7ven

    Joined:
    Apr 18, 2011
    Messages:
    1
    I face this problem for a few day, after searching on google is still not help. Anyone help fix it. my fileupload control is not placed in updatepanel but it' hasFile properties still alway return false.

    Code:
    <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>
    and here is my master page :

    Code:
    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="admin_main.master.cs" Inherits="admin_main" %>
    
    <%@ Register src="Controls/admin_MenuControl.ascx" tagname="MenuControl" tagprefix="uc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>UniqueDesign - Administration Site</title>
    
        <link href="css/admin.css" rel="stylesheet" type="text/css" />
    
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
    <form id="form1" runat="server" >
    <div id="mainFrame">
        <div id="header">
            <div style="float:left;">
                <img alt="" src="Images/UniqueLogo.png" />
            </div>
            <div id="accountInfo" runat="server" style="float:right; text-align:right; padding:0 10px 0 0">
                <div>
                     <span style="color: #fff;"><%= ((UniqueDesign.Entities.User)Session[UniqueDesign.GlobalResources.AdminLogin]) != null ?
                             "Welcome, " + ((UniqueDesign.Entities.User)Session[UniqueDesign.GlobalResources.AdminLogin]).Name : ""
                             %></span>
                </div>
                <div>
                    <a href="admin_ChangePassword.aspx" style="color:#FFFFFF;" target="_self">Change password</a>
                </div>
                <div>
                    <a href="admin_LogOut.aspx" style="color:#FFFFFF;" target="_self">Log Out</a>
                </div>
            </div>
            <div style="clear:both;"></div>
        </div>
            <uc1:MenuControl ID="MenuControl1" runat="server" />
        <div id="body_frame">
            <div id="title">
                <div id="title_content"> 
                    <asp:ContentPlaceHolder ID="titlePlaceHolder" runat="server" />
                </div>
            </div>
            <div>
                <div style="float: left; width: auto; height: auto; margin: 0; padding: 0;"><asp:ContentPlaceHolder id="ContentPlaceHolderCategory" runat="server" /></div>
                <div style="float: left; width: auto; height: auto; margin: 0; padding: 0;"><asp:ContentPlaceHolder id="ContentPlaceHolder" runat="server" /></div>
            </div>
        </div>
    </div>
    </form>
    </body>
    </html>
    my code behind :

    Code:
    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);
                    }
                }
    
    
    when i debbuged it, it's HasFile properties return alway is false, and

    fupImage.PostedFile.ContentLength = -2 but it still got filename and filetype.

    here is my web.config :

    Code:
    <?xml version="1.0"?>
    <!-- 
                    Note: As an alternative to hand editing this file you can use the 
                    web admin tool to configure settings for your application. Use
                    the Website->Asp.Net Configuration option in Visual Studio.
                    A full list of settings and comments can be found in 
                    machine.config.comments usually located in 
                    \Windows\Microsoft.Net\Framework\vx.x\Config 
    -->
    <configuration>
            <configSections>
                    <section name="uploadSettings" type="darrenjohnstone.net.FileUpload.UploadConfigurationSection, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb"/>
                    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                                    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                                    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                                            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                                            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                                            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                                            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                                    </sectionGroup>
                            </sectionGroup>
                    </sectionGroup>
            </configSections>
            <uploadSettings
                    allowedFileExtensions=".gif,.png,.jpg,.jpeg"
                    scriptPath="jscript/FileUpload/upload_scripts"
                    imagePath="jscript/FileUpload/upload_images"
                    cssPath="jscript/FileUpload/upload_styles"
                    showProgressBar="true"
                    showCancelButton="true"
                    enableManualProcessing="true"
            />
            <appSettings>
            </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>
    </configuration>
     
    Ne7ven, Apr 18, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chak
    Replies:
    2
    Views:
    990
  2. GaryDean

    FileUpload Control within UpdatePanel

    GaryDean, May 4, 2008, in forum: ASP .Net
    Replies:
    6
    Views:
    590
    Anil Abraham
    May 28, 2008
  3. Carlos
    Replies:
    1
    Views:
    427
    Patrice
    Mar 12, 2010
  4. crea
    Replies:
    7
    Views:
    260
    Alf P. Steinbach /Usenet
    May 19, 2011
  5. kurtj@ev1.net
    Replies:
    10
    Views:
    314
    Thomas 'PointedEars' Lahn
    Feb 16, 2006
Loading...

Share This Page