Textbox Custom Attribute

R

Ryan

Hello everyone,

I am brand new to writing custom controls and I thought I would start
with an easy one. Adding an attribute, OriginalValue, to a textbox.

I got this together, and while stepping through it, the property is
setting the viewstate properly with the given value, but on the
postback I am getting empty quotes.

I realize I should probably obtain a book and read further, but by
following examples, it looks correct and I am at wits-end . . . here is
the complete custom class. I get the Text value back properly, but not
the OriginalValue.

As you can see, I tried the AddAttributesToRender and I tried putting
the RenderContents method in (seeing examples with and without it).
None of this helped. I'm sure I am just missing something obvious. I
thought by putting the values in viewstate, they would be available
during a postback.


Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<Assembly: TagPrefix("EBMS.Web.UI.WebControls", "EBMS")>

<DefaultProperty("Text"), ToolboxData("<{0}:ValueChangedTextBox
runat=server></{0}:ValueChangedTextBox>")> _
Public Class ValueChangedTextBox
Inherits TextBox
Implements INamingContainer

<Bindable(True), DefaultValue(""), Category("Appearance"),
Localizable(True), Description("This stores the original value to be
used in a comparison.")> Property OriginalValue() As String
Get
Dim strOriginalValue As String =
CStr(ViewState("OriginalValue"))
If strOriginalValue Is Nothing Then
Return String.Empty
Else
Return strOriginalValue
End If
End Get

Set(ByVal Value As String)
ViewState("OriginalValue") = Value
End Set
End Property

'Protected Overrides Sub AddAttributesToRender(ByVal writer As
System.Web.UI.HtmlTextWriter)

' MyBase.AddAttributesToRender(writer)

' writer.AddAttribute("OriginalValue", OriginalValue)

'End Sub

'Protected Overrides Sub RenderContents(ByVal output As
HtmlTextWriter)
' output.Write(OriginalValue)
'End Sub

End Class

Thank you for any assistance. Have a nice evening,
Ryan
 
R

Ryan

Figured it out. Had to implement the IStateManager, then add the value
to the statebag . . .

Thanks anyway,
Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top