自定义控件中包含 一个checkboxlist 和 一个imageButton 并有张 aa.gif文件。
如何自定义控件中imageButton 的click事件 以及怎么让imageButton 显示aa.gif。主页面如何触发click事件

解决方案 »

  1.   

    在父窗体构造函数里添加
    this.子控件对象.imageButton .Click+=new EventHandler(imageButton _Click);
    在imageButton _Click中处理
      

  2.   

    如果只有一个ImageButton的话可以直接把事件写在用户控件里面显示图片:imageButton.imageurl="../aa.gif" //路径自己去找,控件中有这个属性。imageurl
      

  3.   

    我要重写这个事件,要页面能调用到click事件
    直接这么写imageButton .Click+=new EventHandler(imageButton _Click); 
    页面程序调用不了
    进不到自定义控件的事件中
      

  4.   

    怎么在网页上自定义控件中的Click事件?
      

  5.   

    Default.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %><%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <uc1:WebUserControl1 ID="WebUserControl11" runat="server" OnImgBtnClick="ImgBtnClick"/>
        
        </div>
        </form>
    </body>
    </html>
    Default.aspx.cs:using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;namespace WebApplication2
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {        }        protected void ImgBtnClick(object sender, EventArgs e)
            {
                Response.Write("这个事件是在Default页面触发的!");
            }
        }
    }
    WebUserControl1.ascx:<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication2.WebUserControl1" %>
    <asp:ImageButton ID="ImageButton1" runat="server"  Width="100px" 
        onclick="ImageButton1_Click" AlternateText="单击ImagButton" />
    WebUserControl1.ascx.cs:using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;namespace WebApplication2
    {
        public partial class WebUserControl1 : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {        }        public event EventHandler ImgBtnClick;
            protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
            {
                ImgBtnClick(this, e);
            }        public ImageButton ImgBtn
            {
                get { return ImageButton1; }
                set { ImageButton1 = value; }
            }
        }
    }
      

  6.   

    显示图片:控件中有这个属性"imageurl",设一下就好了呀
      

  7.   

    要用WebControlLibrary 
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication2.WebUserControl1" %>
    <asp:ImageButton ID="ImageButton1" runat="server"  Width="100px" 
        onclick="ImageButton1_Click" AlternateText="单击ImagButton" />
    这段代码怎么写到cs文件里