| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 573 人关注过本帖
标题:自定义一个单击事件问题
只看楼主 加入收藏
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
结帖率:0
收藏
 问题点数:0 回复次数:2 
自定义一个单击事件问题
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>");
    }
}

按钮是显示出来了的,为什么事件触发不了,,,求高手?
搜索更多相关主题的帖子: 单击 定义 
2010-05-27 00:05
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
收藏
得分:0 
怎么没有人回答呢? 求救
2010-05-28 01:29
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
收藏
得分:0 
已解决了。。
2010-05-28 04:27
快速回复:自定义一个单击事件问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019160 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved