Uploading File using AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kmithu
    New Member
    • Jun 2007
    • 11

    Uploading File using AJAX

    Hi friends,

    I want to upload a file on AJAX web page. The HTML code i m using is:

    ----------------------------------------------------------------------------------------
    [code=html]
    <asp:ScriptMana ger ID="ScriptManag er1" runat="server" />
    <asp:UpdatePane l ID="UpdatePanel 1" runat="server">
    <ContentTemplat e>
    <asp:FileUplo ad ID="FileUpload1 " runat="server" />
    <asp:Button ID="Button1" runat="server" OnClick="Button 1_Click" Text="Button" />
    </ContentTemplate >
    </asp:UpdatePanel >
    [/code]
    -----------------------------------------------------------------------------------------
    The problem is that when i run the program the page gets Auto postback and the value in the fileUpload gets cleared. and the error of "object reference cannot be set to null" comes on the below line.....

    string st=FileUpload1. PostedFile.File Name;

    I tried using viewstate but still the problem is of Autopostback... ...
    No effect with triggers and update mode set to conditional.... Please help me out.
    Last edited by Frinavale; Aug 3 '07, 03:08 PM. Reason: Added [code] tags to make more legible
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Often placing a check for not.ispostback helps.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      The FileUpload control is one of the few controls that does not work within an UpdatePanel. It requires a full page PostBack to work.

      Take your FileUpload control out of the UpdatePanel and it will work.

      Cheers!

      -Frinny

      Comment

      • jriddle
        New Member
        • Aug 2007
        • 1

        #4
        This post describes all the controls that dont' currently work in in the updatepanel control (unless you do a full postback via a trigger).

        Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.

        Comment

        Working...