Is it bad to use runat="server" on <tr>?
Asked Answered
M

7

8

I'm supporting an application that uses runat="server" all over the place to show/hide table rows.

For example, in places where there are dependent DropDownLists, the row with the child ddl will be hidden until a value us chosen in the parent ddl.

Is that a bad practice? Is there a better way to do this?

Merrilee answered 27/1, 2011 at 18:44 Comment(0)
J
10

I use runat="server" anytime I need it. So I think you can use it too. :-)

Jerrold answered 27/1, 2011 at 18:47 Comment(0)
C
6

I think that's absolutely terrible practice. First of all you do not need to make the trip to the server to hide and show controls, unless you need new data.

Second, any decent javascript framework will allow you to hide show controls based on the control's id, class name, or whatever css selector. Moreover using a javascript post/get to a generic handler will give you the data that you need without the postback.

I'd suggest using JQuery, or some other alternative.

Crabb answered 27/1, 2011 at 18:52 Comment(1)
it's already making a trip to the server to populate the child DropDownList because of the *gasp* UpdatePanels.Merrilee
T
5

It depends on how much you care about performance. Anything that is marked with runat="server" goes through more processing than just client side tags.

Personally, I've used them before. Especially in the situation where a table cell or table row is relying on data from the server. You can use Javascript or JQuery with a hidden field but you still have to hit the server for the hidden field, so it doesn't buy much.

Tuggle answered 27/1, 2011 at 18:52 Comment(0)
T
3

It's not bad to use runat="server" with standard HTML controls. Often you'll find the use of PlaceHolders to show and hide content on pages, or in ASP.NET MVC you might see the use of inline code blocks such as <% ... %> within the views. On it's own and not in consideration of other design aspects, it's neither good nor bad.

Tablecloth answered 27/1, 2011 at 18:48 Comment(0)
E
1

That's what I do to hide the row containing other server controls. The other options are to use a asp:panel or other container, but that will add more HTML without any gain.

Empoverish answered 27/1, 2011 at 18:47 Comment(2)
asp:PlaceHolder is one way to avoid extra rendered HTMLTablecloth
I was meaning HTML and server tags in the ASPX page itself.Empoverish
B
1

I don't think it's necessarily bad practice. I've done the very same thing plenty of times. I think it's mainly personal preference.

Borgeson answered 27/1, 2011 at 18:48 Comment(0)
S
0

Not at all. ASP.NET supports making any html tag run on the server side. Your alternative is to wrap the tag in a Panel, and hide or show that. If you're not looking for the extra functionality or want to control the output yourself, making an html tag run on the server isn't a problem.

Snuffbox answered 27/1, 2011 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.