views:

43

answers:

2

I've been looking at google for the past few hours, trying to find an issue to a apparently simple problem. I have a UserControl named RolloverLink that basically contains a asp:LinkButton and a <img /> . I tried setting the OnClick handler like this:

<%@ Control Language="C#" AutoEventWireup="true" 
    CodeBehind="RolloverLink.ascx.cs" Inherits="Controls.RolloverLink" %>
<asp:LinkButton  runat="server" ID="mug" OnClick="propagate" 
    CausesValidation="false" onmouseout="MM_swapImgRestore()" >
       <img runat="server" ID="pug" name="<%# pug.ClientID %>" border="0" />
</asp:LinkButton>

I put a breakpoint in the propagate method, but it doesnt stop there. The page does post back (it flashes), but the event doesn't get called.

Here's how my code behind looks like:

public partial class RolloverLink : System.Web.UI.UserControl
{
    private string _imageRl;
    public string Href { get; set; }
    public string ImageUp { get { return pug.Src; } set { pug.Src = value; } }
    public string ImageRl {
        get
        { 
            return _imageRl;
        }
        set
        {
            _imageRl = value;
            mug.Attributes["onmouseover"] = "MM_swapImage('"+pug.ClientID+"','','"+_imageRl+"',1)";
        }
    }
    public string Alt { get { return pug.Alt; } set { pug.Alt = value; } }
    public int Width { get { return pug.Width; } set { pug.Width = value; } }
    public int Height { get { return pug.Height; } set { pug.Height = value; } }
    public event EventHandler Click
    {
        add{click += value; }
        remove { click -= value; }
    }
    private event EventHandler click;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Url.AbsolutePath.EndsWith(Href))
            ImageUp = ImageRl;
    }
    protected void propagate(object sender, EventArgs e)
    {
        EventHandler copy = click;
        if (copy != null)
            copy(this, EventArgs.Empty);
        else
            Response.Redirect(Href);
    }
}

and this is how i use it on my master page:

<pwc:RolloverLink ID="contacts" Href="Contacts.aspx" 
    ImageRl="images/M_contacts_rl.png" ImageUp="images/M_contacts_up.png" 
    Alt="Initech Global : Laurierville, Qu&eacute;bec, Canada" Width="61" 
    Height="17" runat="server" />

Anyone has an idea or a pointer to an idea? Thanks in advance.

A: 

You're adding the click event, then removing it in this code

public event EventHandler Click
{
    add{click += value; }
    remove { click -= value; }
}

I think you're trying to remove a reference to a click event that could be there and then adding a reference to the click event you are defining. Just switch around the remove & add and it should work.

public event EventHandler Click
{
    remove { click -= value; }
    add{click += value; }

}
TheGeekYouNeed
That shouldn't prevent `propagate` from firing. If you look `propagate` tries to fire `click` if it has been set from an external object
Pete Amundson
A: 

This looks like a non-standard way of adding eventhandlers to a click event:

Have you tried the standard syntax:

  _mug.Click += new EventHandler(value);
Daniel Dyson