470,614 Members | 1,572 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Help Me! WebCustomControl

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!
Nov 19 '05 #1
5 1145
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

"Arnold" <no@spam.com> wrote in message
news:Ol*************@TK2MSFTNGP10.phx.gbl...
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!

Nov 19 '05 #2
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.
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

"Arnold" <no@spam.com> wrote in message
news:Ol*************@TK2MSFTNGP10.phx.gbl...
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!


Nov 19 '05 #3
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/de...StateTopic.asp
http://msdn.microsoft.com/library/de...StateTopic.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
"Arnold" <no@spam.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
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.
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

"Arnold" <no@spam.com> wrote in message
news:Ol*************@TK2MSFTNGP10.phx.gbl...
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!



Nov 19 '05 #4
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.

"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
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/de...StateTopic.asp http://msdn.microsoft.com/library/de...StateTopic.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
"Arnold" <no@spam.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
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.
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

"Arnold" <no@spam.com> wrote in message
news:Ol*************@TK2MSFTNGP10.phx.gbl...
> 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!
>
>



Nov 19 '05 #5
Ready. Just with a MyItem array.
THanks again for all!!

"Arnold" <no@spam.com> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
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.

"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
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/de...StateTopic.asp

http://msdn.microsoft.com/library/de...StateTopic.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
"Arnold" <no@spam.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
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.
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> 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
>
> "Arnold" <no@spam.com> wrote in message
> news:Ol*************@TK2MSFTNGP10.phx.gbl...
> > 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!
> >
> >
>
>



Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by wukexin | last post: by
3 posts views Thread by Colin J. Williams | last post: by
7 posts views Thread by Corepaul | last post: by
2 posts views Thread by news | last post: by
reply views Thread by Amar | last post: by
1 post views Thread by Cristian | last post: by
3 posts views Thread by Qwert | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.