M
Mike Lavender
Hello,
I am trying to make a Web Cstom Control with a property which is simply
a reference to another control. This is exactly the same as the validator
type controls which contain a reference to a "ControlToValidate". At first
it seems easy to do, but I cannot figure out how to persist the reference
(i.e. i can easily set the reference on the "properties" window via the
dropdown which is automatically shown and automatically filters for the
appropriate type. I see that the HTML generated for the validator controls
saves the reference name as a string. I have tried playing around with the
attributes Persist, DesignerSerialize, etc. but no luck. I imagine it is
simple, but not apparent to me.
Here is a sample..
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace TestWebControls
{
/// <summary>
/// Summary description for WebCustomControlTest.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControlTest
runat=server></{0}:WebCustomControlTest>")]
public class WebCustomControlTest : System.Web.UI.WebControls.WebControl
{
private string text;
private Label _alabel;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Label ALabel
{
get
{
return _alabel;
}
set
{
_alabel = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
Thanks,
Mike Lavender
I am trying to make a Web Cstom Control with a property which is simply
a reference to another control. This is exactly the same as the validator
type controls which contain a reference to a "ControlToValidate". At first
it seems easy to do, but I cannot figure out how to persist the reference
(i.e. i can easily set the reference on the "properties" window via the
dropdown which is automatically shown and automatically filters for the
appropriate type. I see that the HTML generated for the validator controls
saves the reference name as a string. I have tried playing around with the
attributes Persist, DesignerSerialize, etc. but no luck. I imagine it is
simple, but not apparent to me.
Here is a sample..
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace TestWebControls
{
/// <summary>
/// Summary description for WebCustomControlTest.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControlTest
runat=server></{0}:WebCustomControlTest>")]
public class WebCustomControlTest : System.Web.UI.WebControls.WebControl
{
private string text;
private Label _alabel;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public Label ALabel
{
get
{
return _alabel;
}
set
{
_alabel = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
Thanks,
Mike Lavender