473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AddNewPlaylist.ascx.cs" Inherits="WebControls_AddNewPlaylist" %>
  2.  
  3. Name your playlist:&nbsp;&nbsp;<asp:TextBox ID="PlayListNameTextBox" runat="server"></asp:TextBox><br />
  4. Pick artwork for your playlist:<br />
  5. <br />
  6. Upload custom artwork:<br />
  7.     <asp:FileUpload ID="PlayListFileUpload" runat="server" /><br />
  8. <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
  9. <br />
  10.      <asp:Label ID="StatusLabel" runat="server" Text=""></asp:Label>
The code on the .ascx.cs code page:
Expand|Select|Wrap|Line Numbers
  1.  protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         string playListName = PlayListNameTextBox.Text;
  4.         Boolean fileOK = false;
  5.         String path = Server.MapPath("~/UserPages/PlayListImages/");
  6.         string imagePath;
  7.  
  8.         if (PlayListFileUpload.HasFile)
  9.         {
  10.             String fileExtension = System.IO.Path.GetExtension(PlayListFileUpload.FileName).ToLower();
  11.             String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
  12.             for (int i = 0; i < allowedExtensions.Length; i++)
  13.             {
  14.                 if (fileExtension == allowedExtensions[i])
  15.                 {
  16.                     fileOK = true;
  17.                 }
  18.  
  19.                 if (fileOK)
  20.                 {
  21.                     try
  22.                     {
  23.  
  24.                         PlayListFileUpload.PostedFile.SaveAs(path + PlayListFileUpload.FileName);
  25.                         imagePath = path + PlayListFileUpload.FileName;
  26.                         MusicDbBusinessTear.AddPlayList(playListName, imagePath);
  27.                         StatusLabel.Text = "Playlist Created!";
  28.                         Response.Redirect("~/UserPages/Music.aspx");
  29.                     }
  30.                     catch (Exception ex)
  31.                     {
  32.                         StatusLabel.Text = "Playlist could not be created.";
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     StatusLabel.Text = "Cannot accept files of this type.";
  38.                 }
  39.             }
  40.         }
This user control gets loaded into a placeholder. Any help would be greatly appreciated.
Feb 3 '11 #1
1 15429
Frinavale
9,735 Expert Mod 8TB
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
Feb 7 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets...
4
by: Daisy | last post by:
In my user control: <asp:Button id="btnLogin" runat="server" Text="Login"></asp:Button> And the code-behind: protected override void OnInit(EventArgs e) { btnLogin.EnableViewState = true;...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
4
by: Chad | last post by:
I have a link (.ascx) and that generates an Add form on that page. The autopostback dropdown is within a "If Not IsPostBack Then" statement. The form that is created is all via static html in the...
2
by: Roger Cantillo | last post by:
Hi, In a webform, is it possible to change the OnClick event of a button at runtime? -- Axiom Software, Ltd. 400 Columbus Ave Valhalla, NY 10595 (914) 769-8800
2
by: moondaddy | last post by:
I have an asp.net 2.0 application and put a html button on a web page. I double clicked on the button and it crated the event handler for me and created the stub js function for it like this: ...
8
by: SAL | last post by:
Hello, I have a button on a webform that has an OnClick event defined as such: <asp:Button ID="btnSearchByName" runat="server" Text="Search By Name" OnClick="btnSearchByName_Click" Width="152px"...
0
by: =?Utf-8?B?Sm9obiBIYXJ0ZQ==?= | last post by:
Hi, In the code behind of my ASP.net web page I have code written that is dynamically creating a button. Here is a sample of how I define it. //Define Variable Button btnNext; public void...
7
by: chronic malfeasance | last post by:
Hello, I have a C# .Net 2.0 project. Every single page with a button that contains an OnClick method receives a Compilation Error on run stating the definition for the OnClick method does not...
1
by: munkee | last post by:
A very simple question which I cant answer myself at the meoment due to epic tiredness. I have a combobox in my access 2003 database which is populated with the real names of users taken from a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.