扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:东方欲晓 来源:yesky 2007年11月8日
关键字: Windows
Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Xml Imports System.Collections Namespace CustomControls Public Class Composite Inherits Control Implements INamingContainer Private _filename As String = "bad_words.xml" Private label As Label Private box1 As TextBox Public Property filename() As String Get Return _filename End Get Set _filename = value End Set End Property ' 以用户提交的文本内容为输入参数。如果用户提交的内容包含攻击性言辞, ' 则返回修改后的版本, ' 否则,直接返回原始的文本。 Public Function CheckString(InputString as String) as string Dim alWordList As new ArrayList dim xmlDocPath as string = mappathsecure("bad_words.xml") dim xmlReader as XmlTextreader = new xmlTextReader(xmlDocPath) dim element as string dim output as string dim asterisks as string = "*************************" ' 将定义攻击性言辞的xml文件内容读入到一个ArrayList while (xmlReader.Read()) if xmlReader.NodeType=xmlNodeType.Text then alWordList.Add(xmlReader.Value) end if end while xmlReader.Close() ' 检查用户提交的文本内容,将攻击性言辞替换为适当数量的星号 For Each element in alWordList InputString=InputString.Replace(element, asterisks.substring(1, (element.length))) Next Return InputString End Function Public Property Text() As String Get ' 该方法首先检查ChildControlsCreated属性的当前值。如果该值是false, ' 则调用CreateChildControls方法 EnsureChildControls() Return label.Text End Get Set EnsureChildControls() label.Text = value End Set End Property Public Event Check As CheckEventHandler Protected Overridable Sub OnCheck(ce As CheckEventArgs) RaiseEvent Check(Me, ce) End Sub '创建Composite控件的子控件 Protected Overrides Sub CreateChildControls() Controls.Add(New LiteralControl("<h3>请在下面输入文字内容: ")) '文本输入框 Dim box1 As New Textbox() box1.Text = "" Controls.Add(box1) Controls.Add(New LiteralControl("</h3>")) '按钮 Dim button1 As New Button() button1.Text = "提交" Controls.Add(New LiteralControl("<br>")) Controls.Add(button1) ' 将一个事件句柄加入新创建的按钮对象 AddHandler button1.Click, AddressOf Me.ButtonClicked Controls.Add(New LiteralControl("<br><br>")) label = New Label() label.Height = Unit.Pixel(50) label.Width = Unit.Pixel(500) label.Text = "" Controls.Add(label) End Sub Protected Overrides Sub OnPreRender(e As EventArgs) CType(Controls(1), TextBox).Text = "" End Sub Private Sub ButtonClicked(sender As [Object], e As EventArgs) OnCheck(New CheckEventArgs(CType(Controls(1), TextBox).Text, CheckString(CType(Controls(1), TextBox).Text))) End Sub End Class End Namespace |
' 包含定制事件数据类CheckEventArgs的代码. ' 另外还定义了Check事件的事件句柄 Imports System Namespace CustomControls Public Class CheckEventArgs Inherits EventArgs Private _match As Boolean = False Public Sub New(string1 As String, string2 as String) If string1=string2 Then _match = True End If End Sub Public ReadOnly Property Match() As Boolean Get Return _match End Get End Property End Class Public Delegate Sub CheckEventHandler(sender As Object, ce As CheckEventArgs) End Namespace |
vbc /t:library /out:./bin/CustomControls.dll /r:System.dll /r:System.web.dll /r:System.drawing.dll /r:System.Data.dll /r:System.xml.dll *.vb |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者