Search code examples
asp.netweb-parts

asp.net onclick event not fired


I'm facing a weird problem with my asp.net buttons. All was fine, I was coding a webpart with some ajax panels and buttons, and it was just so near to be finished when a wild error appeared. All my buttons were firing the same method despite I didn't told then so.

Well, I found it was due to a known issue : http://forums.asp.net/t/1567526.aspx/1

I tried to delete the called method to see if the other buttons would go back to their assigned methods, and since then, no more event is fired by buttons. No more... Never...

I put back the method, created a new webpart with new code, restored a backup of my site, reset my server, restarted Visual Studio, And finally I'm trying to create a whole new VS solution with a whole new code. I've just a page with one lonely asp button, And nothing happens...

ascx file :

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PublicationUserControl.ascx.cs" Inherits="CripmeeWebParts.Publication.PublicationUserControl" %>

<asp:Button ID="Valider" runat="server" Text="Valider" />

ascx.cs file

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace CripmeeWebParts.Publication
{
    public partial class PublicationUserControl : UserControl
    {
        protected override void OnLoad(EventArgs e)
        {
            EnsureChildControls();
            base.OnLoad(e);
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Valider.Click += new EventHandler(Valider_Click);
        }

        void Valider_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}

I've tied all this : attach event on the ascx code or on the CreateChildControls, use onCommand event, place button in a <form>, attach debugger to w3 process to see if it go through all my methods.

I'm just out of ideas... Thank you for reading, any suggestion would be usefull.


Solution

  • here comes the solution I've found.

    I still don't know why the event disappeared, but I notice that they are not fired only when I display the webpart from administration panel (site action>settings>webpart library> click on my custom webpart). If I add my webpart to a test page, all is working fine. If someone else have the same issue, I hope he will read this and avoid the week I've lost...

    Thank you all for your time and answers :)