Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2010, 11:14 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default Ways to centralize controls properties ?

Hello,

I was wondering since im working on many controls that have the same properties. Is there a way to centralize controls properties ? Such making some controls share the same properties ? like skin i think do with the style ?

Thanks.
 
Old December 14th, 2010, 11:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For some properties, you can use Skins, but for many others you can't.

What's the kind of data you try to centralize? Maybe there are alternative solutions depending on what you try to accomplish....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 14th, 2010, 11:59 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default

I am working with DevExpress controls and there are properties such ValidationSetting, Width, ErrorTexts etc.. properties dedicated to the control only.. not properties such runat or id or clientinstancename or anything that can't obviously be repeated.
 
Old December 14th, 2010, 01:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

There's no straight forward way to do. You could do it programmatically. Here's an example (assuming you have two TextBox controls in your page):

Code:
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Load
  Dim allTextBoxes As New List(Of TextBox) From {TextBox1, TextBox2}
  For Each textBox As TextBox In allTextBoxes
    textBox.Text = "Some default text"
  Next
End Sub
Alternatively, if it's worth the trouble when you have many controls, you could subclass your controls and initialize their defaults somehow.

Finally, you could create code snippets that have some defaults set. Not the same thing as setting properties to all controls at once, but it may help during development.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Rushino (December 14th, 2010)
 
Old December 14th, 2010, 01:44 PM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default

Thanks for this simple solution. I didn't though about setting them programmatically.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding properties to controls pauliehaha ASP.NET 3.5 Basics 0 June 23rd, 2008 04:56 AM
Access templated controls properties tony_j_hug ASP.NET 2.0 Basics 5 October 17th, 2005 10:44 AM
Accessing Properties in User Controls andyj00 ASP.NET 1.0 and 1.1 Professional 16 August 1st, 2005 07:55 AM
Accessing Properties in User Controls andyj00 Classic ASP Professional 1 May 21st, 2005 02:52 PM
default properties on controls Duncan Pro VB.NET 2002/2003 3 November 15th, 2003 02:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.