C
Cappy
Hi.
I have built a custom control for a collapseable panel. The panel has
an image to which when clicked, fires a client side javascript
function that shows or hides the panel using DHTML. This javascript
funciton is registered to the page on render
This works fine for me except that when a post back occurs for any
reason, because the show/hide all occurs client side, the control
doesnt remember its collapsed state.
I think what I need to do is register an event to the collapse image
thats sets a collapsed propety which is stored in the view state.
I have a property as follows to hold the collapsed state.
[Bindable(true),
Category("Appearance"),
DefaultValue("false")]
public bool Collapsed
{
get
{
if(ViewState["Collapsed"] == null) return false;
return Convert.ToBoolean(ViewState["Collapsed"]);
}
set
{
ViewState["Collapsed"] = value;
}
}
What I need to know is.. how do I make my collapse image button set
this property. Currently.. my image button looks like this.
writer.AddAttribute(HtmlTextWriterAttribute.Name,
"Collapse"+this.UniqueID);
//If started collapsed, show expand image if available, else collapse
image.
if ((Collapsed) && (expandImg.Length > 0))
{
writer.AddAttribute(HtmlTextWriterAttribute.Src, expandImg);
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Src, collapseImg);
}
//Javascript Onlick function to show or hide panel body
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,"toggle('"+this.UniqueID+
"_collapse','"+this.UniqueID+"')");
writer.AddAttribute("hspace","3");
//If mouse over add js
if (collapseOnImg.Length > 0)
{
writer.AddAttribute("onMouseOver", "ImgH.swap(this,'Collapse"+
this.UniqueID +"On');");
writer.AddAttribute("onMouseOut", "ImgH.fade(this,'Collapse"+
this.UniqueID +"Off');");
}
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
how do I make this image set the property of the control on click?
Regards
Amit
I have built a custom control for a collapseable panel. The panel has
an image to which when clicked, fires a client side javascript
function that shows or hides the panel using DHTML. This javascript
funciton is registered to the page on render
This works fine for me except that when a post back occurs for any
reason, because the show/hide all occurs client side, the control
doesnt remember its collapsed state.
I think what I need to do is register an event to the collapse image
thats sets a collapsed propety which is stored in the view state.
I have a property as follows to hold the collapsed state.
[Bindable(true),
Category("Appearance"),
DefaultValue("false")]
public bool Collapsed
{
get
{
if(ViewState["Collapsed"] == null) return false;
return Convert.ToBoolean(ViewState["Collapsed"]);
}
set
{
ViewState["Collapsed"] = value;
}
}
What I need to know is.. how do I make my collapse image button set
this property. Currently.. my image button looks like this.
writer.AddAttribute(HtmlTextWriterAttribute.Name,
"Collapse"+this.UniqueID);
//If started collapsed, show expand image if available, else collapse
image.
if ((Collapsed) && (expandImg.Length > 0))
{
writer.AddAttribute(HtmlTextWriterAttribute.Src, expandImg);
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Src, collapseImg);
}
//Javascript Onlick function to show or hide panel body
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,"toggle('"+this.UniqueID+
"_collapse','"+this.UniqueID+"')");
writer.AddAttribute("hspace","3");
//If mouse over add js
if (collapseOnImg.Length > 0)
{
writer.AddAttribute("onMouseOver", "ImgH.swap(this,'Collapse"+
this.UniqueID +"On');");
writer.AddAttribute("onMouseOut", "ImgH.fade(this,'Collapse"+
this.UniqueID +"Off');");
}
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
how do I make this image set the property of the control on click?
Regards
Amit