Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Composite Controls and Bubbling events (http://www.velocityreviews.com/forums/t755506-composite-controls-and-bubbling-events.html)

Javi 07-08-2003 11:58 AM

Composite Controls and Bubbling events
 
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 07-09-2003 08:02 PM

Re: Composite Controls and Bubbling events
 
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" <javi_javi@hotmail.com> wrote in message
news:0b7d01c34548$31929e00$a501280a@phx.gbl...
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;
}
}




All times are GMT. The time now is 08:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.