|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom Web Control and Default Height/WidthI 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; } } 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 Show quoteHide quote "Sfw_Kris" wrote: > 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; > } > } 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 Show quoteHide quote "Kelly Leahy" wrote: > 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" wrote: > > > 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; > > } > > }
Failed to load viewstate
Push Button Event in datagrid Web Standards Compliance - Autopostback / Javascript off FileUpload, Wizard, and saving the data Dynamic Menu Control in ASP.NET2 User Control question - REPOSTED Using hyperlink control for downloading "Unable to open the physical file" error How do I put bitmaps/images in front of another bitmap? Creating Dynamic FormView Templates |
|||||||||||||||||||||||