Custom Web Control and Default Height/Width

S

Sfw_Kris

Good afternoon,

I have begun creating a custom web control in .NET 2.0. I have overridden
the height and width attributes so that I can supply a DefaultValue that is
more appropriate to the control, however the control does not reflect this
default when dropped into the designer or when run up in a web page. I get
the sense that perhaps I'm not setting the DefaultValue attribute correctly,
or that I've missed some additional piece of coding that is required. I've
included an example of one of my properties below, note I also attempted
setting the DefaultValue as just an integer. Any suggestions?

Thanks.

[DefaultValue(typeof(Unit), "200px")]
public override Unit Height
{
get
{
return this.pnlMain.Height;
}
set
{
this.pnlMain.Height = value;
}
}
 
K

Kelly Leahy

You need to set the value of this property in your constructor as well.

The "DefaultValue" attribute only tells the IDE what default value the
control assumes will be set in the constructor, so that when the value is
equal to this default, it is not stored in the designer generated code.
However, you are still responsible for setting everything to the default
values in the constructor of your control.

Cheers,
Kelly
 
S

Sfw_Kris

Hi Kelly,

I must be having one of 'those' weeks. That makes perfect sense and works
like a charm, thank you very much for your help.

Kris

Kelly Leahy said:
You need to set the value of this property in your constructor as well.

The "DefaultValue" attribute only tells the IDE what default value the
control assumes will be set in the constructor, so that when the value is
equal to this default, it is not stored in the designer generated code.
However, you are still responsible for setting everything to the default
values in the constructor of your control.

Cheers,
Kelly

Sfw_Kris said:
Good afternoon,

I have begun creating a custom web control in .NET 2.0. I have overridden
the height and width attributes so that I can supply a DefaultValue that is
more appropriate to the control, however the control does not reflect this
default when dropped into the designer or when run up in a web page. I get
the sense that perhaps I'm not setting the DefaultValue attribute correctly,
or that I've missed some additional piece of coding that is required. I've
included an example of one of my properties below, note I also attempted
setting the DefaultValue as just an integer. Any suggestions?

Thanks.

[DefaultValue(typeof(Unit), "200px")]
public override Unit Height
{
get
{
return this.pnlMain.Height;
}
set
{
this.pnlMain.Height = value;
}
}
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top