Professional Web Applications Themes

Values not persisting in extender provider - 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() ...

  1. #1

    Default Values not persisting in extender provider

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

  2. #2

    Default Re: Values not persisting in extender provider

    "*no spam*" <i.s.director> wrote in message
    news:10d883d.0410280257.2686b1dfposting.google.co m...
    > 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 Guest

  3. #3

    Default Re: Values not persisting in extender provider

    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

    dotnet_vb_newbie@programmer.net Guest

  4. #4

    Default Re: Values not persisting in extender provider

    Please show us the code which persists the Hashtable.

    <dotnet_vb_newbieprogrammer.net> wrote in message
    news:1099056787.466784.218490c13g2000cwb.googlegr oups.com...
    > 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 Guest

  5. #5

    Default Re: Values not persisting in extender provider

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

    dotnet_vb_newbie@programmer.net Guest

  6. #6

    Default Re: Values not persisting in extender provider

    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

    TechnologyDude@gmail.com Guest

Similar Threads

  1. Replies: 0
    Last Post: August 22nd, 12:58 PM
  2. Replies: 0
    Last Post: August 1st, 03:23 PM
  3. DB2 XML EXTENDER
    By Silvano Attolini in forum IBM DB2
    Replies: 2
    Last Post: July 23rd, 12:05 PM
  4. Text Extender
    By Stanley Sinclair in forum IBM DB2
    Replies: 0
    Last Post: July 5th, 08:56 PM
  5. Xml extender question
    By Roberto Finelli in forum IBM DB2
    Replies: 0
    Last Post: June 27th, 10:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139