在这种情况下哪种重用方法更好 - ascx 或其他

发布于 2024-07-17 01:47:41 字数 324 浏览 9 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不打扰别人 2024-07-24 01:47:42

这种方法对我来说听起来不错 - 控件旨在帮助您重用代码。 我认为一组用户控件在这里就可以很好地工作。

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.

灼痛 2024-07-24 01:47:42

这种方法绝对是可行的,而且如果以后想修改 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.

樱花细雨 2024-07-24 01:47:42

确保将计算逻辑与显示充分分离。 我将使用一个类来实际确定成绩(可能是多个具有良好继承树的类)来实际进行匹配,并且只是在用户控件中适当地呈现。

如果您有多个类(或用于确定特定实例是什么类型的某些属性),您还可以轻松创建一个工厂来实例化用户控件,您将根据传递的计算获得正确的用户控件类型。

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.

傻比既视感 2024-07-24 01:47:42

我是这样理解您的应用程序的:

  1. 您有注册课程的学生。
  2. 学生可以是标准的或自定进度的。
  3. 对于不同类型的学生,每门课程的评分方法是不同的。
  4. 您需要一种根据学生类型显示正确成绩的方法。

我认为您可以使用单个控件来显示成绩,但一定要确保分离您的逻辑。 也许是这样的:

public class Student{
   public GradingType Type {get;set;}
   public List<Course> RegisteredCourses{get;set;}
   //etc...
}

public class Course{
   //etc...
}

public static class GradeCalculator{
   public static CalculateStudentGrade(Student student, Course course){
      //grade logic...
   }

}

Here's how I understand your app:

  1. You have students that are registered for courses.
  2. Students can be standard or self-paced.
  3. The grading method per course is different for different types of students.
  4. You need a way to display the correct grade based on the student's type.

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:

public class Student{
   public GradingType Type {get;set;}
   public List<Course> RegisteredCourses{get;set;}
   //etc...
}

public class Course{
   //etc...
}

public static class GradeCalculator{
   public static CalculateStudentGrade(Student student, Course course){
      //grade logic...
   }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文