composite control and postback data change handling

D

Donal McWeeney

Hi,

I have a composite control that gets created dynamically and contains an
array of checkbox controls and an array of drop down list controls.

All the control postback and rendering works fine - however there is
something that I want to do that I cant figure out how to do.

In my OnLoad handler I was to examine the updated postback values and
populate a new data structure based on these values. I need to do this
before the postback events get raised.

However because the control is created dynamically the postback data does
not get set until the postback data second try event is ran - which is after
the onload event.

Is there a way to hook into this or is the only way to manually add changed
events for each of the control items.

Thanks

Donal
 
S

Steven Cheng[MSFT]

Hi Donal,

From your description, you're developing a custom web server
control(composite control) which will create all the sub controls(control
tree) dynamically. And currently you're wondering how to get the new posted
datas when the contorl is posted back and create new control tree structure
depending on the new values, yes?
If there're anything I didn't understanding correctly, please feel free to
let me know.

As for this problem, here are some of my suggestions:

Generally, as for such a composite control which create control tree
programmatically, I suggest that we put all the sub control's creation code
in the "CreateChildControls" method, this method will be called before the
Load event and also can be recalled in other events (no later than the
PreRender event) so as to adjust the control tree.
And for your problem, I think you can define some control properties which
is persisted in VIEWSTATE which determine how to create the control's
control tree(those sub controls) in the CreateChildControls method. Have
your control implement "IPostBackDataHandler" interface? If so, you can
try making use of the
"bool IPostBackDataHandler.LoadPostData(string postDataKey,
NameValueCollection postCollection)"
interface , this event is fired after LoadViewState and Load , so we can
get the new posted data collections in it and compare them with the old
values in the VIEWSTAET, if different ,replace the properties with the new
values. And you can recall the "CreateChildControls" method to restructure
your control hierarchy when some of that properites are changed (in that
property's accessor).

In addition, here is a former thread in the group discussing on create a
composite control which will adjust the control tree depending on the post
back values:

http://groups.google.com/groups?hl=zh-CN&lr=&threadm=#K2AUqGrEHA.2340@TK
2MSFTNGP11.phx.gbl

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

Donal McWeeney

Hi Steven,

Thanks for the info.

We dont implement the PostBackDataHandler interface in our composite control
as the child controls we create like textboxes etc implement this and their
values get set correctly on the postback.

If I implement the PostBackDataHandler on my composite control will the
child controls have performed postback processing at that stage? Or do I
have to do something in code to get them to perform postback data
processing?

Thanks

Donal
 
S

Steven Cheng[MSFT]

Hi Donal,

Thanks for the response. Yes, if we implement the PostBackDataHandler, we
need to manually do the things to update the control's data properties ,
also childrens. And after some further consideration, I think we don't
actually need to implement that (which may make the problem more complex).

Would you consider putting the post data handing in the post back events
and recreate the sub controls structures at that time? I still thinnk
that'll make the problem much easier.
If you have any other ideas or any further question, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Donal,

Have you got any further progresses or ideas on this issue? If there're
anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

Donal McWeeney

Hi Steven,

I think I'm ok at the moment... will let you know if there is anything else.

Thanks

Donal
 
S

Steven Cheng[MSFT]

Thanks for your followup Donal. Feel free to let me know if you have any
further questions later in your work.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top