locked
Inheriting from existing WebControl viewstate issue RRS feed

  • Question

  • User1454272008 posted

     I have a few very simplified controls shown below.  The first control inherits from Table and adds a row, a cell, and a checkbox with autopostback enabled.  The second control inherits from panel and adds a checkbox with autopostback enabled.  The third inherits from CompositeControl and adds a checkbox with autopostback enabled.

    Only the third one maintains the viewstate (check state) of the checkbox on postback...  What do I need to do to make the other two work??

     

    Public Class TableTestControl
    Inherits Table
    Protected Overrides Sub CreateChildControls()
    MyBase.CreateChildControls()
    'post back test using control that inherits from table
    'create the row, cell and checkbox

    Dim trow As New TableRow()
    Dim tcell As New TableCell()
    Dim cb As New CheckBox()
    'put them together in the correct order
    Me.Rows.Add(trow)
    trow.Cells.Add(tcell)
    tcell.Controls.Add(cb)
    'set auto postback to true for postback test
    cb.AutoPostBack = True
    End Sub
    End Class

    Public Class
    PanelTestControl
    Inherits Panel
    Protected Overrides Sub CreateChildControls()
    MyBase.CreateChildControls()
    'post back test using control that inherits from Panel
    'create the checkbox

    Dim cb As New CheckBox()
    'put them together
    Me.Controls.Add(cb)
    'set auto postback to true for postback test
    cb.AutoPostBack = True
    End Sub
    End Class

    Public Class
    CompositeTestControl
    Inherits CompositeControl
    Protected Overrides Sub CreateChildControls()
    MyBase.CreateChildControls()
    'post back test using control that inherits from Composite Control
    'create the checkbox

    Dim cb As New CheckBox()
    'put them together
    Me.Controls.Add(cb)
    'set auto postback to true for postback test
    cb.AutoPostBack = True
    End Sub
    End Class

      Thanks for any help with this issue.

    --Peter

    Wednesday, December 10, 2008 12:51 PM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that the first and second control are not the composite control, and what you want is to make those controls handle the postback data.

    <o:p> </o:p>

    To develop a Custom (Non-Composite) Control that Handles Postback Data, see:

    <o:p> </o:p>

    http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#noncomposition

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 14, 2008 10:09 PM

All replies

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that the first and second control are not the composite control, and what you want is to make those controls handle the postback data.

    <o:p> </o:p>

    To develop a Custom (Non-Composite) Control that Handles Postback Data, see:

    <o:p> </o:p>

    http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#noncomposition

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 14, 2008 10:09 PM
  • User-1153549114 posted

    Hi, Nai-Dong

    The link is not working any more.

    Can you provide some code sample

    Thanks,
    Iva

    Friday, August 2, 2013 5:13 AM