1 Replies - 287 Views - Last Post: 18 August 2015 - 07:15 AM Rate Topic: -----

#1 klimba  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-July 15

FileUpload not working in UpdatePanel

Posted 18 August 2015 - 07:04 AM

I created something like this
<body>
    <form id="form1" runat="server">
    <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>


I'm checking if file is picture file or not
but I need put this code into UpdatePanel because I have form and two dropdownlist which they update one another
and I received something like this
<body>
    <form id="form1" runat="server">
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
    </div>
    </form>
</body>

but then FileUpload is not working
procedure button_click is like this
 protected void Button1_Click(object sender, EventArgs e)
        {
            //------------- zapis1 obrazka loga ---------------------------
            if (FileUpload1.HasFile)
            {
                //sprawdzamy czy plik jest plikiem graficznym
                string plikNazwa = FileUpload1.FileName;
                string plikRozszerzenie = Path.GetExtension(plikNazwa);
                plikRozszerzenie = plikRozszerzenie.ToLower();

                if (!(plikRozszerzenie == ".jpg" || plikRozszerzenie == ".jpeg" || plikRozszerzenie == ".jpe" ||
                plikRozszerzenie == ".gif" || plikRozszerzenie == ".bmp"))
                {
                    Label1.Text += "<br /><font color=magenta>Plik nie ma rozszerzenia wskazującego na plik graficzny (JPEG, GIF, BMP). Plik nie został przesłany.</font>";
                    return;
                }
                else
                {
                    Label1.Text += "Plik jest plikiem graficznym. ";
                }
            }
        }


Is This A Good Question/Topic? 0
  • +

Replies To: FileUpload not working in UpdatePanel

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: FileUpload not working in UpdatePanel

Posted 18 August 2015 - 07:15 AM

Do you with certainty that FileUpload1.HasFile is true?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1