Losing value on postback

S

Stanley

I have a WYSISYG server control that I have built. I am having problems
getting the text out of it on post back. I have the code below to handle the
postback. However, when I load the control in my ASPX page and try to do:

Response.Write(myControl.Text)

I get nothing. When debugging I found that the value is there until control
goes back to my ASPX page and it attempts to get the text value. so through
the code below the text is there as it should be. I have been stuck on this
for two day now and can't seem to figure out why it is clearing the value. I
have tried to store the value in a private variable and in the current
context session variable. All get set to nothing. This is a must have item
that I cannot purchase so I have to get this working. Thanks for any help.

Public Event TextChanged As EventHandler
Public Property Text() As String
Get
Return CType(Me.ViewState("Text"), String)
End Get
Set(ByVal Value As String)
Value = Replace(Value, "\", "&#92") '\ is a Special
Character, Replace with \\
Value = Replace(Value, "'", "&#146") ' ' is cause of
Error, replace with \'
Value = Replace(Value, vbCrLf, " ")
Value = Replace(Value, """", """)
Me.ViewState("Text") = Value
End Set
End Property

Public Function LoadPostData(ByVal postDataKey As String, ByVal
postCollection As System.Collections.Specialized.NameValueCollection) As
Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
Dim currentValue As String = Me.Text
Dim postedValue As String = postCollection(postDataKey)
If currentValue Is Nothing Or Not postedValue.Equals(currentValue)
Then
Me.Text = postedValue
Return True
End If
Return False
End Function

Public Sub RaisePostDataChangedEvent() Implements
System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
OnTextChanged(EventArgs.Empty)
End Sub

Protected Overridable Sub OnTextChanged(ByVal e As EventArgs)
RaiseEvent TextChanged(Me, e)
End Sub
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top