Rules for using HTML tag attributes in ASP tags?

R

Randall Parker

I'm wondering if there are general rules for the use of HTML attributes with ASP tags?

For example, one can set an id for an asp:DataGrid and it will show up as the id for
the resulting HTML table.

So then can one set, say, a class for an asp:DataGrid and all other asp tags that map
one-to-one to HTML tags and have it pass thru? I'd like to use class in particular to
map the resulting generated HTML to CSS names. I just tried this and this worked. The
CLASS showed up with the table tag as an attribute. Is it usually supposed to work?

Also, asp:DataGrid maps to table. So then can one just put cellpadding or other legal
attributes of a table as attributes for an asp:DataGrid attribute and have them pass
thru?

Doing this sort of thing with HTML tag attributes with ASP.Net tags seems to work.
But I'm wondering if this is considered normal practice or practice to avoid except
in rare cases or what?
 
K

Karl Seguin

For the most part, unrecognized ASP.Net attributes are simply added to the
Attributes collection and outputted as-is. It can be useful in a number of
situations, and I've certainly done it now and again. However, sometimes
the two conflict. For example, specifying onClick on many controls invokes
the server-side method, hence you need to use xxx.Attributes.Add("OncClick",
"blah();"); in code. Never done it with class (which is a C#/vb.net
keyword), but you should first check if there's an asp.net control
alternative, such as cssClass

Karl
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top