ASP .NET:动态负载控制VS可见=真 [英] ASP .NET: Dynamic load controls vs Visible = true

查看:116
本文介绍了ASP .NET:动态负载控制VS可见=真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个建议?让我解释一下我想达到的目标!

我有很多用户使用的一个页面,每个用户都有如管理员,操作员,普通用户不同的作用。

当客户端打开网页我要显示一组控件(按钮),这取决于他们的角色。

管理员被允许做x和y,但普通用户是不允许做这些动作。

Which one is recommended ? Let me explain what I want to achieve !
I have one pages used by many users, every user has a different Role like admin, operator, normal user.
When a client open that page I want to display a set of controls (buttons) which depends on their Role.
admin is allowed to do x and y, but a normal user is not allowed to do these actions.

为了达到我想要做的,哪种方法是最好的?

我是否应该定义HTML的所有控件然后切换Visible属性,或者动态加载所需的控制?

In order to achieve what I want to do, which approach is the best one ?
Should I define all controls in HTML then toggle Visible property, or dynamically load needed controls ?


有关可见=假我担心服务器的处理时间。即使HTML标记不发送到客户端为可见=虚假的控制,我知道的控制仍然由ASP .NET加载,甚至处理,但他的HTML结果不写入到输出流。

For Visible = false I'm worried about server processing time. Even if HTML markup is not sent to the client for a Visible = false control, I know that the control is still loaded by ASP .NET and maybe even processed, but his HTML result is not written to the output stream.

有关动态加载控件,一个不方便的是,他们需要在回发重新初始化,也存在一些问题,事件和回传。

For dynamically loaded control, one inconvenient is that they need to be reinitialized on Postback, also there are some problems with events and postback.

推荐答案

我不会做它作为动态增益是不值得的复杂性或感知的节省。此外,如果你设置的visible = false ,记住的视图状态的控制仍处于启用状态。如果你担心来回数据和处理更大的视图状态,请确保您禁用视图状态的所有控件或包含它们父面板。您将有同样的不便保持在回发的状态,这样做虽然动态

I wouldn't do it dynamically as the gain is not worth the complexity or perceived savings. Also if you set visible = false, keep in mind that the viewstate is still enabled for your controls. If you are worried about the back and forth data and dealing with a larger viewstate, make sure you disable the viewstate for all the controls or for a parent panel that contains them. You will have the same inconvenience for maintaining their state on postback as doing it dynamically though.

此外,这样做非动态更容易保持到下一个家伙用code工作。布局是显而易见的,更容易直观比试图找出code时,将到哪里。

Also, doing it non-dynamically is much easier to maintain to the next guy working with the code. The layout is obvious and easier to visualize than trying to figure out what code when is putting what where.

创建控件动态确实没有得到你太多可言,除了视图状态的排斥,也许微不足道处理服务器端。我想你会发现它很难甚至能够衡量多大的noticable差别,即使在之间,非视图状态的控制和动态有将它们加入到所​​需的开销负担。

Creating controls dynamically really doesn't gain you much at all except for the exclusion of viewstate and maybe negligable processing server side. I think you would find it difficult to even measure much of a noticable difference, even under load between, a non-viewstate control and the overhead of dynamically having to add them as needed.

最后,它更容易这样做动态,为什么不先来最简单的路线,看看它是否是一个问题。如果它确实成为一个问题,那么完善它在必要时。

Lastly, it's easier to not do it dynamically so why not take the easiest route first and see if it is a problem. If it does become an issue then refine it where necessary.

这篇关于ASP .NET:动态负载控制VS可见=真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆