dynamic user control event handler and page communication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wee Bubba

    dynamic user control event handler and page communication

    my user control (usercontrol1.a scx) is added dynamically into a
    placeholder on page_load. within usercontrol1.as cx there is a button.
    When a user presses this button I want the page to reload with a
    different user control (usercontrol2.a scx)

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

    myPlaceHolder.C ontrols.RemoveA t(0);
    myPlaceHolder.C ontrols.Add(Loa dControl("userc ontrol2.ascx")) ;

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

    thanks

  • Natty Gur

    #2
    Re: dynamic user control event handler and page communication

    Hi,

    You can always use System.Web.Http Context.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(o bject sender, System.EventArg s e)
    {
    PlaceHolder oPH =
    (PlaceHolder)(( System.Web.UI.P age)System.Web. HttpContext.Cur rent.Handler
    ).FindControl(" PlaceHolder1");
    oPH.Controls.Re moveAt(0);
    oPH.Controls.Ad d(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!

    Comment

    • Wee Bubba

      #3
      re:dynamic user control event handler and page communication

      thanks a lot pal. that code worked for me.

      Comment

      Working...