I made the following control that inherits from WebControl
then in my default.aspx.vb file I haveCode:Imports Microsoft.VisualBasic Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Public Class tb Inherits WebControl Protected _labelText As String Protected _value As String Protected _name As String Public Property LabelText() As String Get Return _labelText End Get Set(ByVal value As String) _labelText = value End Set End Property Public Property Value() As String Get Return _value End Get Set(ByVal value As String) _value = value End Set End Property Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter) Dim tmp As String = "<label for='" & Name & "'>" & LabelText & "</label><input id='" & Name & "' type='text' value='" & Value & "' />" writer.Write(tmp) End Sub Protected Overridable Function GetValue(ByVal Collection As Collections.Specialized.NameValueCollection) As Boolean Me.Value = HttpContext.Current.Request(Name) Return True End Function Protected Sub Page_Init(ByVal Sender As Object, ByVal E As EventArgs) Handles Me.Init GetValue(Page.Request.Form) End Sub End Class
I don't understand why the value of the textbox isn't retained after postbackCode:Dim newTB As tb = New tb newTB.Name = "cat" newTB.LabelText = "My cat's name " placeholder.Controls.Add(newTB)
I tried to inherit directly from TextBox but then the render doesn't stick and the label doesn't appear.
Does anyone know what I can do to make this work?
bsw




Reply With Quote