Values not persisting in extender provider

G

Guest

I'm experimenting with a provider to extend WebControl TextBox
validation. Everything shows up ok in the designer. However, if you
close and reopen the aspx file, the values don't seem to persist. Any
ideas what could cause this? Here's a snippet of the definition code.
I can provide more code if it would help...

<Serializable(), _
ProvideProperty("RequiredField", GetType(WebControl)), _
ProvideProperty("ErrorColor", GetType(WebControl)), _
ProvideProperty("RegularExpression", GetType(WebControl))> _
Public Class TextBoxValidator
Inherits System.ComponentModel.Component
Implements IExtenderProvider

#Region " Component Designer generated code "

Public Sub New(ByVal Container As
System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub
 
J

John Saunders

*no spam* said:
I'm experimenting with a provider to extend WebControl TextBox
validation. Everything shows up ok in the designer. However, if you
close and reopen the aspx file, the values don't seem to persist. Any
ideas what could cause this? Here's a snippet of the definition code.
I can provide more code if it would help...

<Serializable(), _
ProvideProperty("RequiredField", GetType(WebControl)), _
ProvideProperty("ErrorColor", GetType(WebControl)), _
ProvideProperty("RegularExpression", GetType(WebControl))> _
Public Class TextBoxValidator
Inherits System.ComponentModel.Component
Implements IExtenderProvider

#Region " Component Designer generated code "

Public Sub New(ByVal Container As
System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

So, where did you store the three property values from each text box? That
probably has something to do with the question of whether or not the
properties persist.

John Saunders
 
D

dotnet_vb_newbie

The values were stored in a hashtable. I've seen a few google posts
saying there was a problem/bug serializing hashtables. Do you know if
the bug has been fixed? If not, can anybody point to a vb workaround?

Here's the section of the code which stores the data into the
hashtable. I'm assuming that I don't need to do anything special in
the code to maintain state as long as the controls have EnableViewState
set to True.
---------------------------------------------------------------------------------------

Private htTextProps As New Hashtable

Private Function addPropertyValue(ByVal ctrl As WebControl) As
TextExtendedProperties
'-- If the TextExtendedProperties class for the textbox in
question
'-- is in the hashtable, return it to the caller.
If htTextProps.Contains(ctrl) Then
Return CType(htTextProps(ctrl), TextExtendedProperties)
Else

'-- If the TextExtendedProperties class is not in the
'-- hashtable for this control then add it

Dim tbProperties As New TextExtendedProperties
htTextProps.Add(ctrl, tbProperties)

'-- We register a handler (i.e., listener) to trap the
'-- validating event of each textbox we are validating
Dim tbCaller As TextBox = CType(ctrl, TextBox)
AddHandler tbCaller.TextChanged, AddressOf
tbValidateHandler

'-- Return the TextExtendedPRoperties class to the caller
'-- so the relevant property can be set.
Return tbProperties
End If
End Function
 
D

dotnet_vb_newbie

Hmm, I'm thinking that might be the problem :) I'd assumed that
everything would get persisted automatically. I'm not sure how to code
things to make the hashtable persist...

Sorry if this is a dumb question, but any suggestions on how to code it
(or pointers that might help me figure it out)?
 
T

TechnologyDude

Does this look about right? Do I need to actually call either of these
routines or will the system take things from here?
============================================================
Protected Overridable Function SaveViewState() As Object
Dim sf As New SoapFormatter
Dim fs As New FileStream("DataFile.soap", FileMode.Create)
Try
sf.Serialize(fs, htTextProps)
Catch e As SerializationException
Debug.WriteLine("Failed to serialize. Reason: " &
e.Message)
Throw
Finally
fs.Close()
End Try
Return htTextProps
End Function
Protected Overridable Sub LoadViewState(ByVal savedState As Object)
If Not (savedState Is Nothing) Then
Dim fs As New FileStream("DataFile.soap", FileMode.Open)
Try
Dim formatter As New SoapFormatter

' Deserialize the hashtable from the file and
' assign the reference to the local variable.
savedState = DirectCast(formatter.Deserialize(fs),
Hashtable)
Catch e As SerializationException
Debug.WriteLine("Failed to deserialize. Reason: " &
e.Message)
Throw
Finally
fs.Close()
End Try
End If
End Sub
End Class
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top