优势和asp.net UserControl的缺点 [英] Advantages and disadvantages of usercontrol in asp.net

查看:123
本文介绍了优势和asp.net UserControl的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否有人告诉我,如果我要在我的项目,就像我可以使用用户控件? FF那么为什么,如果不是为什么不呢?

Can some one please tell me if I should use user controls in my project as much as I can? Ff so why and if not why not?

推荐答案

这是一个有趣的问题;但一想到这种方式。

It's an interesting question; but think of it this way.

您刚刚写一个表,列出所有的用户。你显示这个网站的用户列表页面上。

You've just written a table, listing all of your users. You show this on the List Users page of your website.

在查找用户页面中,您可能希望能够向用户展示列表。你像以前那样重写相同的HTML,code,JavaScript中,CSS?或者你重新使用控制,这次加入的能力,通过用户名或其他属性筛选?

On the "Find User" page, you might want to be able to show a list of users. Do you rewrite the same HTML, code, javascript, CSS as before? Or do you reuse the control, this time adding the ability to filter by a user name or other attributes?

从本质上讲,用户控件在那里打包你的网站的可重复使用的位。而不是到处都重复着同样的code,可以在用户控件包起来,只是加入适当的标签简单地把它添加到你想要的任何页面。

Essentially, user controls are there to package up reusable bits of your website. Rather than repeating the same code everywhere, you can package it up in a user control, and simply add it to any page you want just by adding the appropriate tag.

另外,你刚才做了一个控制项目负责与某些功能处理 - 所有的逻辑,因为它是在一个地方,并从其他code分开。这是一个重要的概念也一样,它停止所有code被混在一起。在用户例如,您可以通过接口与用户的列表交互,而不是与其他code可能会做不同的事情混合。这就是所谓的 SRP ,可以是一件好事。

Also, you have just made ONE control in your project responsible for dealing with some functionality - all of the logic for it is in one place and separated from other code. This is an important concept too, as it stops all of your code being jumbled together. In the users example, you can interact with a list of users through an interface, rather than mixing it with other code that might do different things. This is called SRP and can be a good thing.

作为一个实际的例子,我们有一个显示了我们的产品列表的控制。我们可以重用查找屏幕上的同一控制,管理员界面,像这样的产品屏幕,并在产品展示您选择画面。这code含有大量的逻辑,那就是在一个地方,因此它可以很容易地维护,它可以非常简单地太重用。

As a practical example, we have a control that shows a list of our products. We can reuse the same control on the Find screen, the Admin screen, the "Products Like this" screen, and on the "Products you have chosen" screen. This code contains a lot of logic that is all in one place so it can be maintained easily, and it can be reused very simply too.

用户控件可以是一个非常好的事情。所以,你应该使用它们,当你觉得你可以打包一组现有控件,HTML等,这使得它们可重复使用,并且更易于维护。

User Controls can be a very good thing. So you should use them when you feel like you can package up a group of existing controls, HTML etc. It makes them reusable, and much easier to maintain.

还有一个自定义控制的概念 - 这些通常是现有控件的重新实现 - 你可能有一个ExtendedTextBox,例如,验证文本有人类型它

There is also the concept of custom controls - these are usually reimplementations of existing controls - you might have an ExtendedTextBox, for example, that validates the text as someone types it.

您可以阅读有关这两种控制这里更

You can read more about both kinds of controls here

这篇关于优势和asp.net UserControl的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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