<%@ Page Language="VB" %>
<%@ Register TagPrefix="ACME" Namespace="MyCustomControls" Assembly="CustomControls"%>
File: CustomControl.cs
using System;
using System.Web;
using System.Web.UI;
using System.Collections.Specialized;
namespace MyCustomControls {
public class CustomControl : Control, IPostBackDataHandler {
public event EventHandler TextChanged;
protected virtual void OnTextChanged(EventArgs e) {
TextChanged(this, e);
}
public bool LoadPostData(String PostDataKey, NameValueCollection Values) {
string strOldValue = this.Message;
string strNewValue = Values[PostDataKey];
if (strOldValue != strNewValue) {
this.Message = strNewValue;
return true;
}
return false;
}
public void RaisePostDataChangedEvent() {
OnTextChanged(EventArgs.Empty);
}
public string Message {
get {
return ViewState["Message"].ToString();
}
set {
ViewState["Message"] = value;
}
}
protected override void Render(HtmlTextWriter Output) {
Output.Write("");
}
}
}
File: CustomControl.vb
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Collections.Specialized
Namespace MyCustomControls
Public Class CustomControl : Inherits Control : Implements IPostBackDataHandler
public Event TextChanged(obj as object, e as eventargs)
protected sub OnTextChanged(e as EventArgs)
RaiseEvent TextChanged(Me, e)
end sub
Public Function LoadPostData(PostDataKey As String, Values As NameValueCollection) As Boolean Implements IPostBackDataHandler.LoadPostData
dim strOldValue as String = Me.Message
dim strNewValue as String = Values(postDataKey)
if not strOldValue = strNewValue
Me.Message = strNewValue
return true
end if
return false
End Function
Public Sub RaisePostDataChangedEvent() Implements IPostBackDataHandler.RaisePostDataChangedEvent
OnTextChanged(EventArgs.Empty)
end sub
public property Message as string
Get
Message = ViewState("Message").ToString
End Get
Set
ViewState("Message") = value
End Set
end property
Protected Overrides Sub Render(Output as HtmlTextWriter)
Output.Write("")
End Sub
End Class
End Namespace