Hi all, How do it create/access my own properties for elements in C# that I will use in JS. and how do I access properties that are avaiable in Html but don't appear to be exposed in the c# set like the border property for tables I know I can do it with styles and classes, but it seems like a limp around as opposed to the most robust way to do it. Thanks in advance.
+9
A:
The Attributes
property of the WebControl
base class is what you're looking for. Example:
MyControl.Attributes["myattr"] = "examplevalue";
Ken Browning
2009-03-19 16:31:49
Thank you so much. That was it. Any suggestions for the table attribute: border. C# wants to set it to 0 by default and changing the attribute only adds another border=1.
Praesagus
2009-03-19 18:58:33
There's a BorderWidth property on the Table class. Have you explored that property?
Ken Browning
2009-03-19 19:02:11
+1
A:
The most robust as well as the most correct way of doing it is though CssClass property and a class defined inside a .css file.
One reason to this is that if you have a designer who only touches CSS, they can change styles without touching your C# source code. If you don't have a designated CSS person, layer separation is still beneficial - just imagine looking though source code to change border color.
Separating CSS, source code and JS as much as you can is the advisable practice.
gnomixa
2009-03-19 17:41:36
Thanks for the larger picture considerations. I will keep that in mind as I choose which to put where.
Praesagus
2009-03-19 18:54:32