LinkButton的自定义(未完成)

来源:互联网 发布:百度seo一本通 下载 编辑:程序博客网 时间:2024/04/28 22:03

如有不明白的地方欢迎加QQ群14670545 探讨

没有处理完成啊,先把基本的提示效果放上来:

接着上面一节(样式表和部分代码请到前两节查看哦)

1.ICustomControl接口:

namespace CustomerWebControls{    /// <summary>    /// 自定义控件的统一接口    /// </summary>    public interface ICustomControl    {        //...    }}

2.枚举类新增操作文本HandlerType:

namespace CustomerWebControls{    /// <summary>    /// 按钮操作文本    /// </summary>    public enum HandlerType    {        新增,        删除,        修改,        提交    }}

3.CCLinkButton类:

using System;using System.ComponentModel;using System.Web.UI.WebControls;namespace CustomerWebControls{    public class CCLinkButton : LinkButton, ICustomControl    {        /// <summary>        /// 是否增加客户端提示        /// </summary>        [Bindable(true), Category("Appearance"), DefaultValue(false), Localizable(true)]        public bool ShowTip        {            get { return ViewState["ShowTip"] != null ? (bool)ViewState["ShowTip"] : false; }            set { ViewState["ShowTip"] = value; }        }        /// <summary>        /// 文本框的样式        /// </summary>        [Bindable(true), Category("Appearance"), DefaultValue(HandlerType.删除), Localizable(true)]        public HandlerType LinkHandlerText        {            set { ViewState["LinkHandlerText"] = value; }            get { return ViewState["LinkHandlerText"] != null ? (HandlerType)ViewState["LinkHandlerText"] : HandlerType.删除; }        }        protected override void OnPreRender(EventArgs e)        {            base.OnPreRender(e);            this.Text = LinkHandlerText.ToString();            if (Enabled)            {                string strOnClickJS = string.Empty;                if (ShowTip)                    strOnClickJS = "return confirm('确定要" + LinkHandlerText.ToString() + "吗?') ";                if (!string.IsNullOrEmpty(strOnClickJS))                    Attributes["onclick"] = strOnClickJS;            }            else                this.Attributes.Remove("onclick");        }    }}


4.生成一下,引用一下。页面上加一个样式表:

<style type="text/css">    .link_btn{padding:5px 12px; letter-spacing:3px;}</style>
拖一个CCLinkButton到页面上去,添加一下属性:

<cc1:CCLinkButton runat="server" ID="likbtnText" CssClass="submit link_btn" LinkHandlerText="删除" ShowTip="true"></cc1:CCLinkButton>
效果如下:


没有处理完,等会找个好点的弹窗完善一下界面,再增加回调处理就完美了


原创粉丝点击