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

dynamic user control event handler and page communication

P: n/a
my user control (usercontrol1.ascx) is added dynamically into a
placeholder on page_load. within usercontrol1.ascx there is a button.
When a user presses this button I want the page to reload with a
different user control (usercontrol2.ascx)

if i add the button to the main page I can do this within the button
event handler:

myPlaceHolder.Controls.Add(LoadControl("usercontro l2.ascx"));

but if I put this code inside the button event handler in my
usercontrol1.ascx it doesnt work. how do i communicate my event
handler code from my user control to the parent page placeholder


Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a

You can always use System.Web.HttpContext.Current.Handler which holds
reference to the current page, which is the current handler). Then by
FindControl you can find your place holder and abuse it as much as you
want, have fun


private void Button1_Click(object sender, System.EventArgs e)
PlaceHolder oPH =
(PlaceHolder)((System.Web.UI.Page)System.Web.HttpC ontext.Current.Handler
oPH.Controls.Add(LoadControl("webusercontrol2.ascx "));

Natty Gur[MVP]

blog :
Mobile: +972-(0)58-888377
*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

P: n/a
thanks a lot pal. that code worked for me.

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.