Popular Posts
Asynchronous and deferred JavaScript execution explained Normal execution <script> This is the default behavior of the <script> element. Parsing of the HTML code pauses while the scr... JSON Foramter <html> <head>     <title>JSON Formater</title>     <style type="text/css">     body{         margin:... Wrong text encoding while Jsoup parse document While page encoding is different with content type encoding declaration. Jsoup will get wrong text decode content. To avoid this problem, As...
Blog Archive
Stats
Bug. FileUpload within UpdatePanel
Example below : the FileUpload2 will work, but FileUpload1 won't.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="local_Default" %>

<!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 runat="server">
    <title>FileUpload & UpdatePanel</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <div>
            FileUpload component within in UpdatePanel</div>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <div>
                        <asp:FileUpload ID="FileUpload1" runat="server" />
                    </div>
                    <div>
                        <asp:Button ID="Button1" runat="server" Text="確認" OnClick="Button1_Click" />
                    </div>
                    <asp:Label ID="Label1" runat="server"></asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        <div>
            <div>
                FileUpload</div>
            <div>
                <asp:FileUpload ID="FileUpload2" runat="server" />
            </div>
            <div>
                <asp:Button ID="Button2" runat="server" Text="確認" OnClick="Button2_Click" />
            </div>
            <asp:Label ID="Label2" runat="server"></asp:Label>
        </div>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class local_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            Label1.Text = FileUpload1.PostedFile.FileName;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (FileUpload2.HasFile)
        {
            Label2.Text = FileUpload2.PostedFile.FileName;
        }
    }
}