By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

Event handling with Web User Control

P: n/a
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

May 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

-Brock
http://staff.develop.com/ballen

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

May 6 '06 #2

P: n/a

Brock Allen wrote:
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.

-Brock
http://staff.develop.com/ballen

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


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

May 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.