I copied this example code directly out of the help file ...
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Collections
Imports System.Collections.Specialized
Namespace CustomWebFormsControls
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class MyTextBox
Inherits Control
Implements IPostBackDataHandler
Public Property Text() As String
Get
Return CType(Me.ViewState("Text"), String)
End Get
Set
Me.ViewState("Text") = value
End Set
End Property
Public Event TextChanged As EventHandler
Public Overridable Shadows Function LoadPostData( _
postDataKey As String, _
postCollection As System.Collections.Specialized.NameValueCollection) _
As Boolean Implements IPostBackDataHandler.LoadPostData
Dim presentValue As String = Text
Dim postedValue As String = postCollection(postDataKey)
If presentValue Is Nothing Or Not presentValue.Equals(postedValue) Then
Text = postedValue
Return True
End If
Return False
End Function
Public Overridable Shadows Sub RaisePostDataChangedEvent() _
Implements IPostBackDataHandler.RaisePostDataChangedEvent
OnTextChanged(EventArgs.Empty)
End Sub
Protected Overridable Sub OnTextChanged(e As EventArgs)
RaiseEvent TextChanged(Me, e)
End Sub
Protected Overrides Sub Render(output As HtmlTextWriter)
output.Write("<INPUT type= text name = " & Me.UniqueID & _
" value = " & Me.Text & " >")
End Sub
End Class
End Namespace
I then compiled it and used it in a page as follows...
<%@ Register TagPrefix="myTextBox" Namespace="CustomWebFormsControls" Assembly = "myTextBox" %>
<script runat="server">
Sub submitBtnClick(sender as Object, e as eventargs)
lbl.Text = myTB.Text
End Sub
</script>
<html>
<head>
<title>myRichTextBox</title>
</head>
<body>
<form runat="server">
<myTextBox:MyTextBox id="myTB" runat="server" /><br />
<asp:button id="btnSubmit" text="Submit" onclick="submitBtnClick" runat="server" /><br />
<asp:label id="lbl" runat="server" />
</form>
</body>
</html>
The textbox and button both render fine, but when I enter some text and click the button I get a server error "System.NullReferenceException: Object reference not set to an instance of an object."!
Have I done something wrong, or is the example wrong?
Martin
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."Douglas Adams