문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

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.

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.

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.

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top