English 中文(简体)
LinkButton inuserControl post re but do not fire OnClick
原标题:LinkButton in UserControl posts back but does not fire OnClick

我有一个名为“滚动链”的用户群,基本上包含一个<代码>:LinkButton和<img />。 我试图将奥克克普勒同起来:

<%@ 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>

我在<编码>propagate方法中设置了一个空白点,但该指示意在停止。 该网页还击(闪电),但活动没有打上。

这里,我的法典如何看待:

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);
    }
}

这也是我如何在总页上使用:

<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" />

是否有任何想法或观点?

问题回答

您重新添加点击事件,然后将此事删除。

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

我认为,你试图删除提及可能发生的一个点击事件的内容,然后添加提及你正在界定的点击事件。 就在拆除和安放点上开关;增加,应当工作。

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

}

这看起来像在一次点击活动中增加事件处理员的非标准方式:

1. 您是否尝试过标准辛迪加:

  _mug.Click += new EventHandler(value);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签