• Grumpy Wookie

  • Archives

  • Top Posts

  • Recent Visitors

  • Blog Stats

    • 350,382 hits

ASP : FileUpload control + AJAX = not-worky-work

Have been grappling with a problem relating to the ASP:FileUpload control within .NET 2.0 pages. These are heavily reliant on AJAX, including tabs, date pickers and so on. But – one tab within the page is requiring a FileUpload control – and this doesn’t work with the Save button I’ve implemented. It turns out that it’s related to the (wonderful) partial-postback aspect of AJAX :

As many people have noticed in their AJAX-enabled pages, file uploads do not work when doing an async postback.

Found this article : Why don’t file uploads work during async postbacks ?

Well – if it wants a FULL postback, I’ll friggin’ give it what it wants !! I’ve ended up implementing TWO UpdatePanels – and TWO Save buttons – as below – with one hidden / shown depending on the tab being displayed. This way, the tab that has the ASP:FileUpload control will do a full postback, and can use the file name, etc.

<asp:updatepanel ID=”mSaveUpdatePanel” runat=”server” >

      <contenttemplate>

            <asp:Button runat=”server” ID=”btnSave” Text=”Save” OnClick=”btnSave_Click” />

      </contenttemplate>

</asp:updatepanel>

————————————————————————————————-

<asp:updatepanel ID=”mSaveUpdatePanelWithFullPostback” runat=”server” >

      <Triggers>

            <asp:PostBackTrigger ControlID=”btnSaveWithFullPostback” />

      </Triggers>

      <contenttemplate>

            <asp:Button runat=”server” ID=”btnSaveWithFullPostback” Text=”Save” OnClick=”btnSave_Click” />

      </contenttemplate>

</asp:updatepanel>

Both of these “click” events call the same function, just that one uses a “PostBackTrigger”.

Advertisements

3 Responses

  1. thanks for pointing this out!

  2. thank u

    but the page is going to refresh how to avoid it

  3. You don’t need two update panels, you just need to specify a PostBackTrigger for the file Upload button in your updatepanel.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: