all groups > asp.net building controls > october 2004 >
You're in the

asp.net building controls

group:

Values not persisting in extender provider


Values not persisting in extender provider i.s.director NO[at]SPAM gmail.com
10/28/2004 3:57:05 AM
asp.net building controls:
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

Re: Values not persisting in extender provider John Saunders
10/28/2004 2:12:51 PM
[quoted text, click to view]

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

Re: Values not persisting in extender provider dotnet_vb_newbie NO[at]SPAM programmer.net
10/29/2004 6:33:07 AM
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
Re: Values not persisting in extender provider John Saunders
10/29/2004 5:50:29 PM
Please show us the code which persists the Hashtable.

[quoted text, click to view]

Re: Values not persisting in extender provider dotnet_vb_newbie NO[at]SPAM programmer.net
10/30/2004 11:24:54 AM
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)?
Re: Values not persisting in extender provider TechnologyDude NO[at]SPAM gmail.com
10/31/2004 4:47:13 AM
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
AddThis Social Bookmark Button