Tags for Custom Server Control, as defined in ToolboxData attribute...

A

awburns

I have a custom server control I've written, which I've subclassed
from the System.Web.UI.Control class.

When I drag it from the toolbar to the page, the following text is put
into the aspx source:

<cc1:MyControl ID="MyControl1" runat="server">
</cc1:MyControl>

What I'd really like is to include some default attributes and values
in the default tag. I tried changing the ToolboxData attribute, which
is currently:

[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]

to

[ToolboxData("<{0}:MyControl runat=server SomeProp='SomeValue'></
{0}:MyControl>")]

But all that happened then is that the text in the aspx source was
created without an ID attribute.

I've tried setting the DefaultValue attribute of 'SomeProp', and even
changing it so it always returns a value:

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("DefaultPropValue")]
[Localizable(true)]
public string SomeProp
{
get
{
String s = (String)ViewState["SomeProp"];
return ((s == null) ? "DefaultPropValue" : s);
}

set
{
ViewState["SomeProp"] = value;
}
}

Despite this, the aspx tags are still created without extra
attributes.

Clearly this is possible, and I'm doing something wrong, but I'm
damned if I can figure out what...

Thanks in advance,
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top