.NETGURU
Composite Controls and ViewState
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcontrolsvb' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Chris Wooldridge

what does it take to get a listbox in a composite control to save its =
view state?
I've been round and round with this and just cant seem to get it to =
work, and cant find any samples.

Does anyone have a sample of a compsite control that does simliar? or =
can tell me what i am missing?

-------------component code-----------
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:addremovebox =
runat=3Dserver></{0}:addremovebox>")> Public Class addremovebox

Inherits System.Web.UI.WebControls.WebControl

Public WithEvents NotSelectedBox As New WebControls.ListBox()
Public WithEvents SelectedBox As New WebControls.ListBox()
Public WithEvents AddButton As New WebControls.Button()
Public WithEvents AddAllButton As New WebControls.Button()
Public WithEvents RemoveButton As New WebControls.Button()

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")> =
Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text =3D Value
End Set
End Property

Protected Overrides Sub CreateChildControls()

Dim table1 As New WebControls.Table()
Dim tablerow1 As New WebControls.TableRow()
Dim tablerow2 As New WebControls.TableRow()
Dim tablerow3 As New WebControls.TableRow()
Dim cellNotSelectedBox As New WebControls.TableCell()
Dim cellSelectedBox As New WebControls.TableCell()
Dim cellAddButton As New WebControls.TableCell()
Dim cellRemoveButton As New WebControls.TableCell()
Dim celllabel As New WebControls.TableCell()
table1.Controls.Add(tablerow1)
table1.Controls.Add(tablerow2)
table1.Controls.Add(tablerow3)
tablerow1.Controls.Add(celllabel)
tablerow2.Controls.Add(cellNotSelectedBox)
tablerow2.Controls.Add(cellAddButton)
tablerow2.Controls.Add(cellSelectedBox)
tablerow3.Controls.Add(cellRemoveButton)
cellNotSelectedBox.Controls.Add(NotSelectedBox)
cellSelectedBox.Controls.Add(SelectedBox)
cellAddButton.Controls.Add(AddButton)
cellRemoveButton.Controls.Add(RemoveButton)
celllabel.Text =3D "This Is a text Cell"
AddButton.Text =3D ">>>"
RemoveButton.Text =3D "<<<"
NotSelectedBox.SelectionMode =3D =
Web.UI.WebControls.ListSelectionMode.Multiple
SelectedBox.SelectionMode =3D =
Web.UI.WebControls.ListSelectionMode.Multiple
cellNotSelectedBox.RowSpan =3D 2
cellSelectedBox.RowSpan =3D 2
celllabel.ColumnSpan =3D 3
Controls.Add(table1)

End Sub

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e =
As System.EventArgs) Handles AddButton.Click

Do Until NotSelectedBox.SelectedIndex =3D -1
SelectedBox.Items.Add(NotSelectedBox.SelectedItem)
NotSelectedBox.Items.Remove(NotSelectedBox.SelectedItem)
Loop

End Sub

Private Sub RemoveButton_Click(ByVal sender As Object, ByVal e As =
System.EventArgs) Handles RemoveButton.Click
Do Until SelectedBox.SelectedIndex =3D -1
NotSelectedBox.Items.Add(SelectedBox.SelectedItem)
SelectedBox.Items.Remove(SelectedBox.SelectedItem)
Loop
Dim mysort As New SortedList()
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
Try
mysort.Add(myitem.Text, myitem.Value)
Catch
mysort.Add(myitem.Text & "_", myitem.Value)
End Try
Next
NotSelectedBox.Items.Clear()
Dim i As Integer
For i =3D 0 To mysort.Count - 1
Dim myitem1 As New ListItem()
myitem1.Text =3D mysort.GetKey(i)
myitem1.Value =3D mysort.GetByIndex(i)
NotSelectedBox.Items.Add(myitem1)
Next

End Sub

Private Sub AddAllButton_Click(ByVal sender As Object, ByVal e As =
System.EventArgs) Handles AddAllButton.Click
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
SelectedBox.Items.Add(myitem)
Next
NotSelectedBox.Items.Clear()
End Sub

End Class

------------Page Code--------------------

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents PlaceHolder1 As =
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
=20

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub =
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As =
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
If IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol =3D Me.LoadControl("subclassaddremove.ascx")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If
InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As =
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New WebControls.ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol =3D Me.LoadControl("subclassaddremove.ascx")
mycontrol.NotSelectedBox.Items.Add("test this")
addremovebox1.NotSelectedBox.Items.Add("test")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If

End Sub

End Class

Reply to this message...
 
    
Ollie Cornes

I've got this working by using this.Page.Request.Form[...] - i.e. manually
wrenching the values from the POST data and crowbar-ing them into the
control at render. This seems deeply inelegant, but I haven't yet found out
how to do it better.

Ollie
--
Click here to reveal e-mail address
.NET Books - http://www.cornes.org/books/

----- Original Message -----
From: "Chris Wooldridge" <Click here to reveal e-mail address>
To: "aspngcontrolsvb" <Click here to reveal e-mail address>
Sent: Thursday, January 03, 2002 5:21 PM
Subject: [aspngcontrolsvb] Composite Controls and ViewState

what does it take to get a listbox in a composite control to save its view
state?
I've been round and round with this and just cant seem to get it to work,
and cant find any samples.

Does anyone have a sample of a compsite control that does simliar? or can
tell me what i am missing?

-------------component code-----------
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:addremovebox
runat=server></{0}:addremovebox>")> Public Class addremovebox

Inherits System.Web.UI.WebControls.WebControl

Public WithEvents NotSelectedBox As New WebControls.ListBox()
Public WithEvents SelectedBox As New WebControls.ListBox()
Public WithEvents AddButton As New WebControls.Button()
Public WithEvents AddAllButton As New WebControls.Button()
Public WithEvents RemoveButton As New WebControls.Button()

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub CreateChildControls()

Dim table1 As New WebControls.Table()
Dim tablerow1 As New WebControls.TableRow()
Dim tablerow2 As New WebControls.TableRow()
Dim tablerow3 As New WebControls.TableRow()
Dim cellNotSelectedBox As New WebControls.TableCell()
Dim cellSelectedBox As New WebControls.TableCell()
Dim cellAddButton As New WebControls.TableCell()
Dim cellRemoveButton As New WebControls.TableCell()
Dim celllabel As New WebControls.TableCell()
table1.Controls.Add(tablerow1)
table1.Controls.Add(tablerow2)
table1.Controls.Add(tablerow3)
tablerow1.Controls.Add(celllabel)
tablerow2.Controls.Add(cellNotSelectedBox)
tablerow2.Controls.Add(cellAddButton)
tablerow2.Controls.Add(cellSelectedBox)
tablerow3.Controls.Add(cellRemoveButton)
cellNotSelectedBox.Controls.Add(NotSelectedBox)
cellSelectedBox.Controls.Add(SelectedBox)
cellAddButton.Controls.Add(AddButton)
cellRemoveButton.Controls.Add(RemoveButton)
celllabel.Text = "This Is a text Cell"
AddButton.Text = ">>>"
RemoveButton.Text = "<<<"
NotSelectedBox.SelectionMode =
Web.UI.WebControls.ListSelectionMode.Multiple
SelectedBox.SelectionMode =
Web.UI.WebControls.ListSelectionMode.Multiple
cellNotSelectedBox.RowSpan = 2
cellSelectedBox.RowSpan = 2
celllabel.ColumnSpan = 3
Controls.Add(table1)

End Sub

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddButton.Click

Do Until NotSelectedBox.SelectedIndex = -1
SelectedBox.Items.Add(NotSelectedBox.SelectedItem)
NotSelectedBox.Items.Remove(NotSelectedBox.SelectedItem)
Loop

End Sub

Private Sub RemoveButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RemoveButton.Click
Do Until SelectedBox.SelectedIndex = -1
NotSelectedBox.Items.Add(SelectedBox.SelectedItem)
SelectedBox.Items.Remove(SelectedBox.SelectedItem)
Loop
Dim mysort As New SortedList()
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
Try
mysort.Add(myitem.Text, myitem.Value)
Catch
mysort.Add(myitem.Text & "_", myitem.Value)
End Try
Next
NotSelectedBox.Items.Clear()
Dim i As Integer
For i = 0 To mysort.Count - 1
Dim myitem1 As New ListItem()
myitem1.Text = mysort.GetKey(i)
myitem1.Value = mysort.GetByIndex(i)
NotSelectedBox.Items.Add(myitem1)
Next

End Sub

Private Sub AddAllButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles AddAllButton.Click
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
SelectedBox.Items.Add(myitem)
Next
NotSelectedBox.Items.Clear()
End Sub

End Class

------------Page Code--------------------

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents PlaceHolder1 As
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
If IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol = Me.LoadControl("subclassaddremove.ascx")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If
InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New WebControls.ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol = Me.LoadControl("subclassaddremove.ascx")
mycontrol.NotSelectedBox.Items.Add("test this")
addremovebox1.NotSelectedBox.Items.Add("test")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If

End Sub

End Class

| [aspngcontrolsvb] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolsvb.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Scott Watermasysk (VIP)
Ollie/Chris,

Here is something I have been working on that might help.

It is still very rough, but I think it will apply. I am working on a control
that will render a data entry form.

Right now it only creates a label, textbox, and RequiredFieldValidator. But
it does handle postbacks and gives you access to the text property via:
TestOne.Text.

It is in C#. Damn. Oh well. I hope this helps.

An example:
<TAN:TANFormBuilder runat = "Server" id= "TFB">
    <TanTextBox id = "TestOne" Text = "Hello" LabelText = "This is the
first box">
    <TanTextBox id = "TestTwo" Text = "World!" LabelText = "This is the
second box">
</TAN:TANFormBuilder>

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace TAN.CustomControls {

    public class FormControlBuilder : ControlBuilder
    {
        public override Type GetChildControlType(string tagName,
IDictionary attribs)
        {
            if(tagName == "TanTextBox")
            {
                return typeof(TanTextBox);
            }
            return null;
        }

    }

    [ControlBuilderAttribute(typeof(FormControlBuilder))]
    [ParseChildren(false)]
    public class TANFormBuilder : Control
    {
        //public Hashtable items = new Hashtable();
        public ArrayList items = new ArrayList();
        protected override void AddParsedSubObject(Object obj)
        {
            if(obj is TanTextBox)
            {
                items.Add(obj);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            foreach(TanTextBox ttb in items)
            {
                Controls.Add(ttb);
            }
        }
        
    } //close class

    public class TanTextBox : Control, INamingContainer
    {
        private TextBox tb;
        protected override void CreateChildControls()
        {
         tb = new TextBox();
         tb.ID = "tb";
         tb.Text = Text;

         RequiredFieldValidator validator1 = new
RequiredFieldValidator();
         validator1.ControlToValidate = "tb";
         validator1.Text = "*";
         validator1.ToolTip = validator1.ErrorMessage = "You must
enter your name.";
         validator1.Display = ValidatorDisplay.Dynamic;

         Label l = new Label();
         l.Text = LabelText;
         Controls.Add(l);
         Controls.Add(new LiteralControl(" "));
         Controls.Add(tb);
         Controls.Add(new LiteralControl(" "));
         Controls.Add(validator1);
        }
        private string _tb;
        public string Text
        {
         set
         {
            ViewState["Text"] = value;
            _tb = value;
         }
         get {
            if (tb != null)
            {
                if(tb.Text != "")
                {
                    return tb.Text;
                }
            }
            string s = (string)ViewState["Text"];
            if (s == null)
            {
                return _tb;
            }
            else
            {
                return s;
            }
         }

        }
        private string _labeltext;
        public string LabelText
        {
            set
            {
                _labeltext = value;
            }
            get
            {
                if(_labeltext != null)
                {return _labeltext;}
                else
                {return String.Empty;}
            }
        }
    } //close class
}//close namespace

-----Original Message-----
From: Ollie Cornes [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 03, 2002 1:25 PM
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] Re: Composite Controls and ViewState

I've got this working by using this.Page.Request.Form[...] - i.e. manually
wrenching the values from the POST data and crowbar-ing them into the
control at render. This seems deeply inelegant, but I haven't yet found out
how to do it better.

Ollie
--
Click here to reveal e-mail address
.NET Books - http://www.cornes.org/books/

----- Original Message -----
From: "Chris Wooldridge" <Click here to reveal e-mail address>
To: "aspngcontrolsvb" <Click here to reveal e-mail address>
Sent: Thursday, January 03, 2002 5:21 PM
Subject: [aspngcontrolsvb] Composite Controls and ViewState

what does it take to get a listbox in a composite control to save its view
state?
I've been round and round with this and just cant seem to get it to work,
and cant find any samples.

Does anyone have a sample of a compsite control that does simliar? or can
tell me what i am missing?

-------------component code-----------
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:addremovebox
runat=server></{0}:addremovebox>")> Public Class addremovebox

Inherits System.Web.UI.WebControls.WebControl

Public WithEvents NotSelectedBox As New WebControls.ListBox()
Public WithEvents SelectedBox As New WebControls.ListBox()
Public WithEvents AddButton As New WebControls.Button()
Public WithEvents AddAllButton As New WebControls.Button()
Public WithEvents RemoveButton As New WebControls.Button()

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub CreateChildControls()

Dim table1 As New WebControls.Table()
Dim tablerow1 As New WebControls.TableRow()
Dim tablerow2 As New WebControls.TableRow()
Dim tablerow3 As New WebControls.TableRow()
Dim cellNotSelectedBox As New WebControls.TableCell()
Dim cellSelectedBox As New WebControls.TableCell()
Dim cellAddButton As New WebControls.TableCell()
Dim cellRemoveButton As New WebControls.TableCell()
Dim celllabel As New WebControls.TableCell()
table1.Controls.Add(tablerow1)
table1.Controls.Add(tablerow2)
table1.Controls.Add(tablerow3)
tablerow1.Controls.Add(celllabel)
tablerow2.Controls.Add(cellNotSelectedBox)
tablerow2.Controls.Add(cellAddButton)
tablerow2.Controls.Add(cellSelectedBox)
tablerow3.Controls.Add(cellRemoveButton)
cellNotSelectedBox.Controls.Add(NotSelectedBox)
cellSelectedBox.Controls.Add(SelectedBox)
cellAddButton.Controls.Add(AddButton)
cellRemoveButton.Controls.Add(RemoveButton)
celllabel.Text = "This Is a text Cell"
AddButton.Text = ">>>"
RemoveButton.Text = "<<<"
NotSelectedBox.SelectionMode =
Web.UI.WebControls.ListSelectionMode.Multiple
SelectedBox.SelectionMode =
Web.UI.WebControls.ListSelectionMode.Multiple
cellNotSelectedBox.RowSpan = 2
cellSelectedBox.RowSpan = 2
celllabel.ColumnSpan = 3
Controls.Add(table1)

End Sub

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddButton.Click

Do Until NotSelectedBox.SelectedIndex = -1
SelectedBox.Items.Add(NotSelectedBox.SelectedItem)
NotSelectedBox.Items.Remove(NotSelectedBox.SelectedItem)
Loop

End Sub

Private Sub RemoveButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RemoveButton.Click
Do Until SelectedBox.SelectedIndex = -1
NotSelectedBox.Items.Add(SelectedBox.SelectedItem)
SelectedBox.Items.Remove(SelectedBox.SelectedItem)
Loop
Dim mysort As New SortedList()
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
Try
mysort.Add(myitem.Text, myitem.Value)
Catch
mysort.Add(myitem.Text & "_", myitem.Value)
End Try
Next
NotSelectedBox.Items.Clear()
Dim i As Integer
For i = 0 To mysort.Count - 1
Dim myitem1 As New ListItem()
myitem1.Text = mysort.GetKey(i)
myitem1.Value = mysort.GetByIndex(i)
NotSelectedBox.Items.Add(myitem1)
Next

End Sub

Private Sub AddAllButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles AddAllButton.Click
Dim myitem As ListItem
For Each myitem In NotSelectedBox.Items
SelectedBox.Items.Add(myitem)
Next
NotSelectedBox.Items.Clear()
End Sub

End Class

------------Page Code--------------------

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents PlaceHolder1 As
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
If IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol = Me.LoadControl("subclassaddremove.ascx")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If
InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Dim addremovebox1 As New LopezWebControls.addremovebox()
Dim listbox1 As New WebControls.ListBox()
Dim mycontrol As WebApplication1.subclassaddremove
mycontrol = Me.LoadControl("subclassaddremove.ascx")
mycontrol.NotSelectedBox.Items.Add("test this")
addremovebox1.NotSelectedBox.Items.Add("test")
Me.PlaceHolder1.Controls.Add(addremovebox1)
Me.PlaceHolder1.Controls.Add(listbox1)
Me.PlaceHolder1.Controls.Add(mycontrol)
End If

End Sub

End Class

| [aspngcontrolsvb] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolsvb.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngcontrolsvb] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolsvb.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Chris Wooldridge
All works fine if the control is on the page already
Its when the control is created dynamically that there is a problem

I have found some reference to Implementing the INamingConatiner but that
interface doesnt seem to exist in BEta 2

"Scott Watermasysk" <Click here to reveal e-mail address> wrote in
message news:554050@aspngcontrolsvb...
[Original message clipped]

Reply to this message...
 
    
Jeffrey Widmer
INamingContainer does exist in Beta 2 it just won't show up in the code
complete in Visual Studio

Try:
Implements System.Web.UI.INamingContainer

To get the viewstate to repopulate your dynamic control try the following:
Make sure that the dynamic control you are creating is contained with a form
tag
<form runat=server>
<MyControl:Me runat=server />
</form>

Add also make sure that the control elements that need to maintain viewstate
are created in the Init event of your dynamic control. LoadViewState occurs
right after init so the dynamic controls must exist at this point for them
to have their data repopulated from the viewstate (in the LoadViewState
event).

Hope this helps,
-Jeff

-----Original Message-----
From: Chris Wooldridge [mailto:Click here to reveal e-mail address]
Sent: Friday, January 04, 2002 9:22 AM
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] Re: Composite Controls and ViewState

All works fine if the control is on the page already
Its when the control is created dynamically that there is a problem

I have found some reference to Implementing the INamingConatiner but that
interface doesnt seem to exist in BEta 2

"Scott Watermasysk" <Click here to reveal e-mail address> wrote in
message news:554050@aspngcontrolsvb...
[Original message clipped]

| [aspngcontrolsvb] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolsvb.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Chris Wooldridge
cant even get it to work just creating a listbox all on its on

Create a listbox in the onload for non postback
recreate a the list box in the init to have view state restored

If done this before with other controls just not a list box

"Jeffrey Widmer" <Click here to reveal e-mail address> wrote in message
news:554648@aspngcontrolsvb...
[Original message clipped]

Reply to this message...
 
    
Jonathan Austin
I am having a little problem that may be similar. I saw below that you are
using tables.
I am dynamically adding a DropDownList but it may still apply to Custom
controls.

It's in a panel. I have a table with three columns. I loop through a
database and add a literal control
in the first two columns and then a dropdownlist in the last one. Then I
have a Button at the bottom.
If I change the selection in the dropdownlist, it doesn't retain the state.

If I add another control dynamically outside of the table, in the panel,
such as another dropdownlist or
textbox, then the state starts to hold.

I know this may be getting a little off topic from here, but maybe it's a
starts. Any body know a solution to
this or why it doesn't work unless you add the other control.

Jonathan

At 02:40 PM 1/4/2002 -0600, you wrote:
[Original message clipped]

Reply to this message...
 
    
Ned Hale
The problem is that your listboxes are always reinitialized in your component. Right now you have the code below in your general section. You want to declare the ListBox variables here "Public WithEvents NotSelectedBox", but only initialize them "Set NotSelectedBox = New WebControls.ListBox()" in your CreateChildControls function. That way will allow the individual controls to manage their own ViewState.

Public WithEvents NotSelectedBox As New WebControls.ListBox()
Public WithEvents SelectedBox As New WebControls.ListBox()
Public WithEvents AddButton As New WebControls.Button()
Public WithEvents AddAllButton As New WebControls.Button()
Public WithEvents RemoveButton As New WebControls.Button()

--------------------------------
From: Ned Hale
Reply to this message...
 
 
System.Collections.ArrayList
System.Collections.Hashtable
System.Collections.IDictionary
System.Collections.SortedList
System.EventArgs
System.Object
System.Reflection.Emit.Label
System.String
System.Web.UI.ControlBuilder
System.Web.UI.ControlBuilderAttribute
System.Web.UI.INamingContainer
System.Web.UI.LiteralControl
System.Web.UI.MobileControls.Label
System.Web.UI.MobileControls.RequiredFieldValidator
System.Web.UI.MobileControls.TextBox
System.Web.UI.Page
System.Web.UI.WebControls.Button
System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.ListBox
System.Web.UI.WebControls.ListItem
System.Web.UI.WebControls.ListSelectionMode
System.Web.UI.WebControls.PlaceHolder
System.Web.UI.WebControls.RequiredFieldValidator
System.Web.UI.WebControls.Table
System.Web.UI.WebControls.TableCell
System.Web.UI.WebControls.TableRow
System.Web.UI.WebControls.TextBox
System.Web.UI.WebControls.ValidatorDisplay
System.Web.UI.WebControls.WebControl
System.Windows.Forms.Label
System.Windows.Forms.ListBox
System.Windows.Forms.TextBox




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification