在这种情况下哪种重用方法更好 - ascx 或其他
我有一个 ASP.NET 应用程序,可以显示不同类型学生的成绩。 有些学生的自定进度课程不包括逾期处罚和测验,而另一些学生则有标准的课堂课程。
因此,在显示学生的成绩时,我确定该学生属于哪个类别,然后适当地呈现成绩。
现在我用条件语句来做到这一点,但我考虑将每个案例放入一个ascx文件中(即一个带有gridView的ascx用于自定进度,一个带有gridView用于课堂,每个ascx都调用我的数据中的数据填充方法访问类)。
我可能需要在应用程序的其他地方重复使用此功能,以在不同页面上显示成绩,因此某种自定义控件似乎是有必要的。
这种做法可行吗?
I've got an ASP.NET application that shows grades for different kinds of students. Some students have a self-paced course that doesn't include late penalties and quizzes, and others have a standard classroom course that does.
So, when displaying a student's grade, I determine which category that student falls in, and then render the grade appropriately.
Right now I do this with conditional statements, but I thought about making each case into an ascx file (i.e. one ascx with a gridView for self-paced, and one with a gridView for classroom, each of which calls data population methods in my data access class).
I may need to re-use this functionality elsewhere in the app, to show grades on different pages, so some kind of custom control seems warranted.
Is this approach feasible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这种方法对我来说听起来不错 - 控件旨在帮助您重用代码。 我认为一组用户控件在这里就可以很好地工作。
This approach sounds good to me - controls are designed to help you reuse code. I think a set of UserControls would work just fine here.
这种方法绝对是可行的,而且如果以后想修改 HTML 的显示方式(新样式等),也可以很容易地进行更改。 我想说 ASCX 是一个很好的方法。
This approach is definitely feasible, and it makes it easy to change if you want to modify the way the HTML is displayed at a later time (new styles, etc.). I would say ASCX is a good approach.
确保将计算逻辑与显示充分分离。 我将使用一个类来实际确定成绩(可能是多个具有良好继承树的类)来实际进行匹配,并且只是在用户控件中适当地呈现。
如果您有多个类(或用于确定特定实例是什么类型的某些属性),您还可以轻松创建一个工厂来实例化用户控件,您将根据传递的计算获得正确的用户控件类型。
Make sure you are adequately separating your calculation logic from the display. I would use a class to actually determine the grades (perhaps multiple classes with a nice inheritance tree) to actually do the match, and the just render appropriately in your user control.
If you have multiple classes (or some property for determining what type a particular isntance is) you could also then easily create a factory to instantiate user controls for you where you will get the correct user control type, based on the calculation passed.
我是这样理解您的应用程序的:
我认为您可以使用单个控件来显示成绩,但一定要确保分离您的逻辑。 也许是这样的:
Here's how I understand your app:
I would think you could get by with a single control for displaying grades but would definitely make sure to separate your logic. Maybe something like: