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. Advertisements

  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

    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.