自定义asp.net控件分析(二)
上一篇分析了自定义控件的基本语法。这次编写一控件来作为实例。
在asp.net中当你想对button的click事件做确认操作,但Button按钮不能满足此要求。就针对此要求来编写自己的控件。
======================================================================
继承:System.Web.UI.WebControls.Button
控件功能:弹出确认消息框
控件属性:message(消息框中显示的信息)
控件方法:不需要
控件事件:不需要
使用方法:“确定”执行按钮的button_click事件,“取消”不执行任何事件。
Imports System.ComponentModel
Imports System.Web.UI
Namespace WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:ConfirmButton runat=server></{0}:ConfirmButton>")> Public Class ConfirmButton
''''继承button
Inherits System.Web.UI.WebControls.Button
''''为其所包含的任何服务器控件提供唯一的命名空间
Implements INamingContainer
Dim _Message As String
''''定义message属性。
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Message]() As String
Get
Return _Message
End Get
Set(ByVal Value As String)
_Message = Value
End Set
End Property
Public Sub New()
_Message = ""
End Sub
''''重写控件的输出
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
''''为控件增加客户端onclick事件。
If Me.Message.Trim <> "" Then Me.Attributes.Add("onClick", "jscript:if(!confirm(''''" & Me.Message & "'''')) return false;")
Me.Attributes.Add("onFocus", "jscript:this.blur();")
MyBase.Render(output)
End Sub
End Class
End Namespace
到此,控件就编写完了,你看是不是很简单。
[C语言系列]NET 中C#的switch语句的语法 [Web开发]动易SiteWeaver版自定义采集标签使用说明 [聊天工具]企业形象“自定义”的权利 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [系统软件]自定义DNS访问国外站点 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构
|