Event handling with Web User Control

W

weboweb

Hail the experts!!!

I'm creating a web user control which displays a hierarchical tree of
items from an xml string passed to the control (from the host page)
through an exposed property.
This xml gets created in the Page_Load method of the host page

Each tree item displayed by the control is a LinkButton object.

This LinkButton fires a CommandEventHandler event (when the user
clicks) that is consumed by the page hosting this control.

Everything perfect so far...

The user loads the page, clicks on one of the items, the event gets
fired, the page performs a postback...

Problem is:

When the host page receives the event fired by the tree control, I
would like at this point to get a different XML from the database, then
have the control redraw itself with a different tree.

But how can I do this, since by the time the event raised by the
control gets processed the Page_Load has already finished and the
control is already displaying the old tree?

If I try !IsPostBack in the Page_Load the event will not fire at all.

Basically my question is how in the heck can I update the tree control
from the event method in the host page other than having the page
reload itself using javascript for example?

Also, what is the use of Events in this scenario? Very little in this
case unless I am headed in the wrong direction completely!!!

Many thanks to all, I will post specific code if required, but for now
it's only concepts I need to clarify.

weBo
 
B

Brock Allen

Change the control such that when you assign the XML it doesn't build itself
immediaetly. Instead have the control wait to build itself until PreRender.
 
W

weboweb

Brock said:
Change the control such that when you assign the XML it doesn't build itself
immediaetly. Instead have the control wait to build itself until PreRender.

Hi Brock,

Thanks for the suggestion. I think I had tried that at some point
already.
Anyway I did an override of OnPreRender method for the control itself
and now the event is not being fired. The page does postback, but the
events are not fired.

What I had to do is save the whole xml damn thing to viewstate, so when
the control reloads it gets the xml from viewstate, then the event
simply adds more xml to it and tells the tree to add the new folders.

I'm not happy with this solution though. There must be a better way of
dealing with this situation I hope!

Thanks,

webO
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top