Why is onclick event not firing when button clicked?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claudiu
    New Member
    • Feb 2011
    • 1

    Why is onclick event not firing when button clicked?

    Hi,

    I have the following code and no matter what I do onclick event for button is not firing. I tried deleting the button, the pages. Redid the code. Moved the web project to a different computer and nothing. It worked a few hours ago.

    Code on the web control .ascx:

    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AddNewPlaylist.ascx.cs" Inherits="WebControls_AddNewPlaylist" %>
    
    Name your playlist:&nbsp;&nbsp;<asp:TextBox ID="PlayListNameTextBox" runat="server"></asp:TextBox><br />
    Pick artwork for your playlist:<br />
    <br />
    Upload custom artwork:<br />
        <asp:FileUpload ID="PlayListFileUpload" runat="server" /><br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <br />
         <asp:Label ID="StatusLabel" runat="server" Text=""></asp:Label>
    The code on the .ascx.cs code page:
    Code:
     protected void Button1_Click(object sender, EventArgs e)
        {
            string playListName = PlayListNameTextBox.Text;
            Boolean fileOK = false;
            String path = Server.MapPath("~/UserPages/PlayListImages/");
            string imagePath;
    
            if (PlayListFileUpload.HasFile)
            {
                String fileExtension = System.IO.Path.GetExtension(PlayListFileUpload.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
    
                    if (fileOK)
                    {
                        try
                        {
    
                            PlayListFileUpload.PostedFile.SaveAs(path + PlayListFileUpload.FileName);
                            imagePath = path + PlayListFileUpload.FileName;
                            MusicDbBusinessTear.AddPlayList(playListName, imagePath);
                            StatusLabel.Text = "Playlist Created!";
                            Response.Redirect("~/UserPages/Music.aspx");
                        }
                        catch (Exception ex)
                        {
                            StatusLabel.Text = "Playlist could not be created.";
                        }
                    }
                    else
                    {
                        StatusLabel.Text = "Cannot accept files of this type.";
                    }
                }
            }
    This user control gets loaded into a placeholder. Any help would be greatly appreciated.
    Last edited by Niheel; Feb 3 '11, 08:45 PM. Reason: please use code tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Have you tried stepping into the code with the debugger.
    It could be that your application never enters the If-Statement on line 8...so it appears as if the click button doesn't do anything.

    (Please note that if you are using a FileUpload control within an UpdatePanel, the file will always be Nothing. In this case, configure your UpdatePanel to perform a full page update when the Button is clicked)

    -Frinny

    Comment

    Working...