Values not persisting in extender provider

Discussion in 'ASP .Net Building Controls' started by *no spam*, Oct 28, 2004.

  1. *no spam*

    *no spam* 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
     
    *no spam*, Oct 28, 2004
    #1
    1. Advertising

  2. "*no spam*" <> wrote in message
    news:...
    > 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
     
    John Saunders, Oct 28, 2004
    #2
    1. Advertising

  3. *no spam*

    Guest

    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
     
    , Oct 29, 2004
    #3
  4. Please show us the code which persists the Hashtable.

    <> wrote in message
    news:...
    > 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
    >
     
    John Saunders, Oct 29, 2004
    #4
  5. *no spam*

    Guest

    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)?
     
    , Oct 30, 2004
    #5
  6. *no spam*

    Guest

    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
     
    , Oct 31, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    Extender Provider not saving state

    Steven, Nov 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    307
    Steven
    Nov 25, 2003
  2. JezB

    Extender Provider for ASP.NET ?

    JezB, Apr 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    377
  3. JezB

    Extender Provider

    JezB, Apr 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    396
  4. JezB
    Replies:
    1
    Views:
    369
  5. JezB

    Property Extender properties not persisting !

    JezB, Jun 22, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    170
Loading...

Share This Page