Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - ASP.NET Button click event not working

I have an ASP.NET (C#) page with some 3rd party controls, some ajaxy stuff and some normal ASP.NET Button controls.

The Button click events do not fire when clicked.

Double-clicking the button in design mode in VS 2008 switches to the code-behind but doesn't create the event handler.

Creating the event handler manually doesn't help.

The whole page is too big to include here, but this is the top bit:

<%@ Page Language="C#" MasterPageFile="~/basewidepage2.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="CompanyCompliance.aspx.cs" Inherits="CompanyCompliancePage" Title="3DSS" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc2" %>
<%@ Register Src="usercontrols/CalendarEx.ascx" TagName="CalendarEx" TagPrefix="uc2" %>
<%@ MasterType VirtualPath="~/basewidepage2.master" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceholder1" runat="Server">

    <script type="text/javascript">
         // a bunch of function declarations
    </script>

...and my button declaration on the page:

<asp:Button ID="LicenseCsvButton" runat="server" Text="Export to CSV" OnClick="LicenseCsvButton_Click" />

...and the code-behind:

protected void LicenseCsvButton_Click(object sender, EventArgs e)
{
    // get data
    CompanyCompliance cc = new CompanyCompliance(Master.theCompany.ID);
    DataTable dt = cc.BusinessLicenses.Tables[0];

    // send to browser as download
    Tools.SendTableAsCsvToBrowser(Response, dt, "LicenseData");
}

Any ideas? could it be the ajax or something? Maybe the 3rd party "obout" grid control?

Update:
I did fix this a month or two ago, so I came back to this question to answer it for posterity but couldn't remember exactly how I fixed it! (Curse you, old age!) I had some limited success by replacing some of the ASP.NET AJAX controls with jQuery UI ones but I think the real solution was that one of the properties in the one of the tags was pointing to a control that no longer existed.

If you're in this same situation, try that and let me know what works in the comments and I'll post the correct answer.

like image 536
MGOwen Avatar asked Sep 16 '09 01:09

MGOwen


1 Answers

During debugging, check the CausesValidation property of your button. For some reason, one of my pages had a button defaulting to "True." When I explicitly set it to "False" everything worked.

like image 108
Charlie A Avatar answered Sep 20 '22 23:09

Charlie A