2017-01-23 42 views
-1

我正在尝试创建一个网站,要求用户选择所提供服务的开始日期和截止日期。目前我正在尝试创建一个例外,如果开始日期是在选定的截止日期之后。我能够把例外,但不知道在哪里抛出异常。我的代码如下:如何在Visual Studio网站中引发异常项目

public partial class CalendarRange : System.Web.UI.UserControl 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (IsPostBack) 
     { 
      // This code will only run on the first page load event 
      this.CalStartDate.SelectedDate = DateTime.Today; 
      this.CalThroughDate.SelectedDate = DateTime.Today; 
     } 
     else 
     { 
      // if the starting date is past the through date 
      if (this.StartDate > this.ThroughDate) 
      { 
        throw new Exception("dates are bogus"); 

      } 
     } 

    } 
    /** 
    * "Get" (accessors) methods for start and through dates 
    * 
    */ 

    public DateTime StartDate 
    { 
     get 
     { 

      return CalStartDate.SelectedDate; 
     } 
    } 

    public DateTime ThroughDate 
    { 
     get 
     { 
      return CalThroughDate.SelectedDate; 
     } 
    } 

} 

我应该在哪里抛出异常,并且它应该是在default.aspx.cs页面或当前页面(CalendarRange.ascx.cs)?

+2

我认为你根本不会抛出异常。您有数据验证问题,可以使用工作流程进行处理。这不是一个你无法从中恢复的例外事件。 – Crowcoder

回答

相关问题