P
Phillyboy123
This seems to be a common issue and one that I have not found a
solution to. What I want to do is theoreticly simple. I have tried
creating webcontrols with simple properties string e.t.c and all work
fine. I am now in the process if trying to create a webcontrol that
contains more complex properties. In this case a Property of type
Button. I've played around with all of the recomended metadata
ParseChildren(true/false), PersistChildren(true/false),
PersistanceMode e.t.c. I've also been using "Developing Microsoft
ASP.NET server controls and components" by Nikhil Kothari and Vandana
Datye" but with no success in this area.
At designtime the control is rendered on the page correctly and the
Properties of the Button within the custom control appear in the
properties toolbar/palette. Changes to the Buttons properties ie. Text
or BackColor seem to take effect when the page is redrawn however
these properties do not persist.
1. There values are lost when the project is rebuilt or ran.
2. The HTML for the aspx page has not changed to reflect the new
property values.
Below is the code for the class.
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
namespace DynamicWebControls.Controls
{
public class TestControl:
System.Web.UI.WebControls.WebControl,INamingContainer
{
Button _myButton;
protected override void CreateChildControls()
{
Controls.Clear();
Controls.Add(MyButton);
}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)
]
public Button MyButton
{
get
{
EnsureChildControls();
if(_myButton==null)_myButton=new Button();
return _myButton;
}
set
{
_myButton = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
MyButton.RenderControl(writer);
}
}
}
Thanks in advance for your help.
Phil.
solution to. What I want to do is theoreticly simple. I have tried
creating webcontrols with simple properties string e.t.c and all work
fine. I am now in the process if trying to create a webcontrol that
contains more complex properties. In this case a Property of type
Button. I've played around with all of the recomended metadata
ParseChildren(true/false), PersistChildren(true/false),
PersistanceMode e.t.c. I've also been using "Developing Microsoft
ASP.NET server controls and components" by Nikhil Kothari and Vandana
Datye" but with no success in this area.
At designtime the control is rendered on the page correctly and the
Properties of the Button within the custom control appear in the
properties toolbar/palette. Changes to the Buttons properties ie. Text
or BackColor seem to take effect when the page is redrawn however
these properties do not persist.
1. There values are lost when the project is rebuilt or ran.
2. The HTML for the aspx page has not changed to reflect the new
property values.
Below is the code for the class.
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
namespace DynamicWebControls.Controls
{
public class TestControl:
System.Web.UI.WebControls.WebControl,INamingContainer
{
Button _myButton;
protected override void CreateChildControls()
{
Controls.Clear();
Controls.Add(MyButton);
}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty)
]
public Button MyButton
{
get
{
EnsureChildControls();
if(_myButton==null)_myButton=new Button();
return _myButton;
}
set
{
_myButton = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
MyButton.RenderControl(writer);
}
}
}
Thanks in advance for your help.
Phil.