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
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