Composite Controls and Bubbling events

Discussion in 'ASP .Net Building Controls' started by Javi, Jul 8, 2003.

  1. Javi

    Javi Guest

    I´m programming a composite WebCustomControl called wcc.
    I want to hide a button, once it's clicked!!!

    And my question is:
    Is there any way to execute the OnBubbleEvent(...) method,
    before than CreateChildControls() ????
    If it´s impossible which is the right way to solve this
    problem?

    Thank´s

    -----------------------

    [ToolboxData("<{0}:wcc runat=server></{0}:wcc>")]
    public class wcc : System.Web.UI.WebControls.WebControl,
    INamingContainer
    {
    private bool m_bShowButton = true;
    private Button cmd = null;

    protected override void CreateChildControls()
    {
    if (this.m_bShowButton)
    {
    this.cmd = new Button();

    this.cmd.ID = "cmd1";
    this.cmd.Text = "Command Button";

    this.cmd.CommandName = "Click";

    Controls.Add (this.cmd);
    }
    else
    System.Diagnostics.Debug.WriteLine
    ("Button Hidden");
    base.CreateChildControls ();
    }

    protected override bool OnBubbleEvent (object sender,
    System.EventArgs e)
    {
    if (e is CommandEventArgs)
    if (((CommandEventArgs) e).CommandName
    == "Click")
    {
    System.Diagnostics.Debug.WriteLine
    ("OnBubbleEvent");
    this.m_bShowButton = false;
    return true;
    }
    return false;
    }
    }
     
    Javi, Jul 8, 2003
    #1
    1. Advertising

  2. Javi

    Ben Guest

    How about:
    1. Create the control in CreateChildControls and add it to the Controls
    collection as usual
    2. Create a property of the control which which stores whether the button
    has been clicked, say "ButtonClicked" of type bool, storing it's the in
    ViewState.
    3. In it's event handler which you added += in CreateChildControls
    3. Override OnPreRender of the base class and in this method ButtonClicked
    is set to true set the button's Visible property to false!

    Ben W

    "Javi" <> wrote in message
    news:0b7d01c34548$31929e00$...
    I´m programming a composite WebCustomControl called wcc.
    I want to hide a button, once it's clicked!!!

    And my question is:
    Is there any way to execute the OnBubbleEvent(...) method,
    before than CreateChildControls() ????
    If it´s impossible which is the right way to solve this
    problem?

    Thank´s

    -----------------------

    [ToolboxData("<{0}:wcc runat=server></{0}:wcc>")]
    public class wcc : System.Web.UI.WebControls.WebControl,
    INamingContainer
    {
    private bool m_bShowButton = true;
    private Button cmd = null;

    protected override void CreateChildControls()
    {
    if (this.m_bShowButton)
    {
    this.cmd = new Button();

    this.cmd.ID = "cmd1";
    this.cmd.Text = "Command Button";

    this.cmd.CommandName = "Click";

    Controls.Add (this.cmd);
    }
    else
    System.Diagnostics.Debug.WriteLine
    ("Button Hidden");
    base.CreateChildControls ();
    }

    protected override bool OnBubbleEvent (object sender,
    System.EventArgs e)
    {
    if (e is CommandEventArgs)
    if (((CommandEventArgs) e).CommandName
    == "Click")
    {
    System.Diagnostics.Debug.WriteLine
    ("OnBubbleEvent");
    this.m_bShowButton = false;
    return true;
    }
    return false;
    }
    }
     
    Ben, Jul 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy

    C# UserControl Bubbling events

    Andy, Oct 27, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    29,719
  2. sleigh
    Replies:
    1
    Views:
    2,691
    sleigh
    Feb 12, 2004
  3. Nidhee

    Bubbling Event in Composite controls

    Nidhee, Jul 31, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    160
    John Saunders
    Aug 2, 2004
  4. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    316
    David Boike
    Aug 7, 2003
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    265
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page