Here's what I'm doing. I removed unnecessary code and
tried to show all that involved Styles and viewstate and
rendering.
I do not have a Render() override. My control is built
during the CreateChildControls() call, using composition.
It is basically a table with some fixed number of rows (no
databinding). I have the ItemStyle property that defines
the Style to be applied to each TableRow. No styles are
applied to any TableCell directly.
So, what is happening is that if I change the Style
directly editing the ASPX markup, the changes are
reflected immediately in the Design view of the page, but
if I change using the Properties window then the changes
are not seen until I manually edit something in the ASPX.
If i change a non-reference property, like SomeLabelText
shown below, I have the "set" accessor to force the
refresh by setting ChildControlsCreated to false.
Thanks for helping.
[
Category("Style"),
Description("blahblahblah"),
DesignerSerializationVisibility
(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)
]
public TableItemStyle ItemStyle
{
get
{
if (itemStyle == null)
{
itemStyle = new Style();
if (IsTrackingViewState)
((IStateManager)itemStyle).TrackViewState();
}
return itemStyle;
}
}
private TableItemStyle itemStyle;
public string SomeLabelText
{
get
{
string o = (string)ViewState
["SomeLabelText"];
return (o == null)?""
;
}
set
{
ViewState["SomeLabelText"] = value;
//force it to rebuild control tree
if(base.HasControls())
{
base.Controls.Clear();
ChildControlsCreated=false;
}
}
}
protected override void CreateChildControls()
{
Controls.Clear();
TableRow tr;
TableCell td;
Table table = new Table();
table.ID = this.ID;
//add a row
tr = new TableRow();
if(itemStyle != null) tr.ControlStyle.MergeWith
(itemStyle);
//create table cells without style (omitted)
//...
table.Controls.Add(tr);
//add more rows similarly ...
this.Controls.Add(table);
}
protected override void LoadViewState(object savedState)
{
object[] data = (object[])savedState;
//first item is the regular viewstate information
base.LoadViewState(data[0]);
//omitted other data
if (data[2] != null)((IStateManager)
this.ItemStyle).LoadViewState(data[2]);
}
protected override object SaveViewState()
{
object[] data = new object[numberOfItems];
//first item is the regular viewstate information
data[0] = base.SaveViewState();
//omitted other data
data[2] = (this.itemStyle != null)?
((IStateManager)this.itemStyle).SaveViewState():null;
return data;
}
protected override void TrackViewState()
{
base.TrackViewState();
if (this.itemStyle != null) ((IStateManager)
this.itemStyle).TrackViewState();
}
public override void RenderEndTag(HtmlTextWriter writer)
{
//empty
//just avoid the default <span> by doing nothing
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
//empty
//just avoid the default </span> by doing nothing
}
--
TJoker
MVP: Paint, Notepad, Solitaire
****************************************
-----Original Message-----
TJ,
Have you tried to merge the style into the the table cell
to whom you want
this custom style applied. Also just like jesse stated,
you will have to
perform this in your render method call if you are
databinding
Can you showcase the code where you are copying the
custom style you exposed
as a property into the table. I have a hunch you are not
merging this style
into the table cell, if you are, show some of this code,
makes a lot easier
to help ;P