UpdatePanels and FileUploads

Before I repost a blog article I wrote a while back I would like to thank Joe Stagner for hooking me up with an account. On to the repost...

 This is a really ugly hack but it got things done for me. Basically what i do is I detect when the file upload control value changes. When it does i toggle on the button that performs a full postback and toggle off the button that performs the async partial postback.

 
<asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
<contenttemplate>
<asp:fileupload runat="server" id="fuTest" width="450px">
<asp:label id="lblStatus" runat="server" text="N/A"><br />
<asp:button runat="server" id="btnPartial" text="Submit" onclick="btnSubmit_Click">
<asp:button runat="server" id="btnFullPostback" text="Submit" onclick="btnSubmit_Click">
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="btnFullPostback">
</triggers>
</asp:UpdatePanel>


Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Me.fuTest.HasFile Then
Me.lblStatus.Text = "No File"
Else
Me.lblStatus.Text = Me.fuTest.FileName
End If
End Sub
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
If Not Page.IsPostBack Then
Me.btnFullPostback.Style.Add("display", "none")
Me.fuTest.Attributes.Add("onchange", "$get('" & btnFullPostback.ClientID & "').style.display = 'block';$get('" & btnPartial.ClientID & "').style.display = 'none';")
End If
End Sub
 

No Comments