No the button click is not in this custom control... it is in another, related custom control.
I have two custom controls (1) ModeLinkButton and (2) EditableTextBox
The concept is pretty simple:
You can register multiple instances of the EditableTextBox to a ModeLinkButton as listeners.
When you click "Edit" in ModeLinkButton it will tell all of its subscribers (ie. EditableTextBoxes) to render as textboxes.
Otherwise, EditableTextBox will render as a label.
Here is the click event from ModeLinkButton
void LinkButton_Click( object sender, EventArgs e )
{
LinkButton lb = ( LinkButton )sender;
switch( lb.CommandName )
{
case "View":
this.State = Enums.State.Edit;
foreach( IEditControl c in this.Subscribers )
c.State = Enums.State.Edit;
break;
case "Cancel":
this.State = Enums.State.View;
foreach( IEditControl c in this.Subscribers )
c.State = Enums.State.View;
break;
case "Apply":
this.State = Enums.State.View;
foreach( IEditControl c in this.Subscribers )
c.State = Enums.State.Apply;
break;
default:
throw new ApplicationException( "Invalid LinkButton CommandName." );
}
}
Here is the EditableTextBox State property:
[DefaultValue( Motivano.Constants.Enums.State.View )]
public Motivano.Constants.Enums.State State
{
get
{
if( HttpContext.Current.Session[ this.ID + "_State" ] == null )
{
this.State = Motivano.Constants.Enums.State.View;
}
return ( Motivano.Constants.Enums.State )HttpContext.Current.Session[ this.ID + "_State" ];
}
set
{
HttpContext.Current.Session[ this.ID + "_State" ] = value;
if( value == Motivano.Constants.Enums.State.Apply )
{
Update( );
}
}
}
As you can see in the setter, if the state is "Apply" then we call the EditableTextbox controls Update() method:
private void Update( )
{
if( this.Txt != null )
this.Value = this.Txt.Text;
this.State = Motivano.Constants.Enums.State.View;
}
The Update() method simply grabs the value from the textbox and plops it into the Value property:
[DefaultValue( "" )]
public string Value
{
get
{
if( ViewState[ this.ID + "_Value" ] == null )
this.Value = String.Empty;
return ViewState[ this.ID + "_Value" ].ToString( );
}
set
{
ViewState[ this.ID + "_Value" ] = value;
}
}
So anyhow, let me know if you see anything that is sticking out!
Thanks