Help Me! WebCustomControl

A

Arnold

Hi,
Im building a WebCustomControl. In my principal class (Inherits from
WebControl), have a property of type MyCollection (Inherits from
CollectionBase), which is a MyItem collection. To mantain the properties of
each MyItem in MyCollection I need set a special ID to each property of
MyItem, and for this, I need access to my principal class, but... each item
of MyCollection is created at desing time... i can't pass an object as
argument in the constructor. I can catch the creation of each MyItem at
design time creating MyCollectionEditor( Inherits from CollectionEditor),
overriding CreateInstance method, i can pass anything to MyItem Constructor,
but can't access to the principal class from MyCollectionEditor, because i
don't know wich object instance MyCollectionEditor (Attirubute).
The question... How to identify the ViewState of each MyItem property if i
can't access to the principal class to set an UniqueID? :(

Thanks!
 
W

William F. Robertson, Jr.

I am assuming your question is how to save each MyItem type from
MyCollection into view state for your principal control so it may be created
on postback.

You should implement IStateManager on MyCollection. In the save/load
ViewState methods of your principal control, you should call the
IStateManager.methods of MyCollection. MyCollection would then go through
and save its viewstate in what ever manner you need to.

You do not need to get the ID of the principal control to work ViewState
properly. The ViewState for MyCollection is placed inside the ViewState
container for a specific Control.

If this doesn't answer your question, or have another one, continue this
thread.

HTH,

bill
 
A

Arnold

I override the LoadViewState and SaveViewState of my principal Control and
never raised the LoadViewState Method, and implement IStateManager in
MyCollection, but I don't know wich instructions set in these methods.
 
W

William F. Robertson, Jr.

Here is the flow you will probably want to do.

public class myControl : WebControl
{
protected override void LoadViewState(object savedState)
{
Pair p = savedState as Pair;
if ( p != null )
{
base.LoadViewState( p.First );
Collection.LoadViewState( p.Second );
}
}

protected override object SaveViewState()
{
object state1 = base.SaveViewState();
object state2 = Collection.SaveViewState();

return new Pair( state1, state2 );
}

public myCollection Collection;
}

public class myCollection : CollectionBase, IStateManager
{
public object SaveViewState()
{
//save the state of the collection and return an object.
}

public void LoadViewState(object state)
{
//load the state from the object passed. It will be the same as was
returned by SaveViewState.
}
}

Here is some additional reference.
http://msdn.microsoft.com/library/d...SystemWebUIControlClassSaveViewStateTopic.asp
http://msdn.microsoft.com/library/d...SystemWebUIControlClassLoadViewStateTopic.asp

This is a more advanced topic and I wish you the best of luck. If you need
any more pointers let me know.

Good luck!

bil
 
A

Arnold

Thanks! Really Thank you for help me.

Now the LoadViewState is raised, but when i save the collection lunch an
error about can't savestate of objects with TypeConverter of
ReferenceConverter, how can I save the collection of MyItems?

Thanks again.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top