在上使用runat =“server”是不是很糟糕?[英]Is it bad to use runat=“server” on ? 本文翻译自  Homer  查看原文  2011-01-27  5243    runatserver/

时间:2021-11-10 15:57:33

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

我正在支持一个应用程序,它在整个地方使用runat =“server”来显示/隐藏表行。

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.

例如,在存在依赖DropDownLists的位置,具有子ddl的行将被隐藏,直到在父ddl中选择的值为止。

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

这是一种不好的做法吗?有一个更好的方法吗?

7 个解决方案

#1


9  

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

我随时都需要使用runat =“server”。所以我认为你也可以使用它。 :-)

#2


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.

其次,任何体面的JavaScript框架都允许您根据控件的id,类名或任何css选择器隐藏show控件。此外,使用javascript post / get to a generic handler将为您提供所需的数据,而无需回发。

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

我建议使用JQuery或其他替代方案。

#3


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.

这取决于你对表现的关注程度。任何标有runat =“server”的东西都经过了比客户端标签更多的处理。

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.

就个人而言,我之前使用过它们。特别是在表格单元格或表格行依赖于来自服务器的数据的情况下。您可以将Javascript或JQuery与隐藏字段一起使用,但仍然必须在服务器上搜索隐藏字段,因此它不会购买太多。

#4


2  

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.

使用标准HTML控件的runat =“server”并不错。通常,您会发现使用PlaceHolders来显示和隐藏页面上的内容,或者在ASP.NET MVC中,您可能会在视图中看到使用内联代码块,例如<%...%>。它本身并没有考虑其他设计方面,它既不好也不坏。

#5


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.

这就是我要隐藏包含其他服务器控件的行。其他选项是使用asp:panel或其他容器,但这将添加更多HTML而没有任何收益。

#6


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.

我认为这不一定是不好的做法。我做了很多次同样的事情。我认为这主要是个人偏好。

#7


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.

一点也不。 ASP.NET支持在服务器端运行任何html标记。您可以选择将标记包装在Panel中,然后隐藏或显示该标记。如果您不是在寻找额外的功能或想要自己控制输出,那么在服务器上运行html标签不是问题。

#1


9  

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

我随时都需要使用runat =“server”。所以我认为你也可以使用它。 :-)

#2


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.

其次,任何体面的JavaScript框架都允许您根据控件的id,类名或任何css选择器隐藏show控件。此外,使用javascript post / get to a generic handler将为您提供所需的数据,而无需回发。

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

我建议使用JQuery或其他替代方案。

#3


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.

这取决于你对表现的关注程度。任何标有runat =“server”的东西都经过了比客户端标签更多的处理。

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.

就个人而言,我之前使用过它们。特别是在表格单元格或表格行依赖于来自服务器的数据的情况下。您可以将Javascript或JQuery与隐藏字段一起使用,但仍然必须在服务器上搜索隐藏字段,因此它不会购买太多。

#4


2  

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.

使用标准HTML控件的runat =“server”并不错。通常,您会发现使用PlaceHolders来显示和隐藏页面上的内容,或者在ASP.NET MVC中,您可能会在视图中看到使用内联代码块,例如<%...%>。它本身并没有考虑其他设计方面,它既不好也不坏。

#5


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.

这就是我要隐藏包含其他服务器控件的行。其他选项是使用asp:panel或其他容器,但这将添加更多HTML而没有任何收益。

#6


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.

我认为这不一定是不好的做法。我做了很多次同样的事情。我认为这主要是个人偏好。

#7


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.

一点也不。 ASP.NET支持在服务器端运行任何html标记。您可以选择将标记包装在Panel中,然后隐藏或显示该标记。如果您不是在寻找额外的功能或想要自己控制输出,那么在服务器上运行html标签不是问题。