Composite Controls and Bubbling events

J

Javi

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;
}
}
 
B

Ben

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;
}
}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top