自定义一个单击事件问题
using System;using System.Web.UI;
using System.Web.UI.WebControls;
using
using System.Drawing;
DLL
namespace MyControl
{ public class MyButton:WebControl{
public event EventHandler Click;
string types;
string text;
public MyButton() : base(HtmlTextWriterTag.Input) { }
public string Types {
get
{
return types;
}
set
{
types = value;
}
}
public string Text {
get
{
return text;
}
set
{
text = value;
}
}
protected override void OnInit(EventArgs e)
{
if (text == null) {
text = "Button1";
}
if (types == null) {
types = "text";
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, types);
writer.AddAttribute(HtmlTextWriterAttribute.Value, text);
base.AddAttributesToRender(writer);
}
protected override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
}
protected void OnClick() {
if (Click != null) {
Click(this, new EventArgs());
}
}
}
}
前台调用(ASPX):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="wo" Assembly="MyControl" Namespace="MyControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<wo:MyButton Types="Button" Text="aa" id ="Button1" runat="server" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>
aspx.cs文件:
using System;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Button1.Click+=new EventHandler(Button1_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('aa')</script>");
}
}
按钮是显示出来了的,为什么事件触发不了,,,求高手?