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.RemoveAt(0);
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
please?

thanks

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


P: n/a
Hi,

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

<CODE>

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

</CODE>
Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
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.