日期验证结果未显示

时间:2014-12-22 18:42:49

标签: c# asp.net visual-studio-2010 validation

我有一个问题,我在两个日期之间做了验证,我们只说第一个是到期日,第二个是价值日。验证规则是到期日减去价值日期,结果放在条款字段上.aspx文件上的代码。

            <asp:Label ID="Label13" CssClass="col-xs-2" runat="server">Value Date : </asp:Label>
              <div class="col-xs-6 col-sm-3">
                    <asp:TextBox CssClass="form-control" ID="uiTxtValDate" runat="server" OnTextChanged="uiTxtValDate_TextChanged" AutoPostBack="true"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="uiTxtValDate" runat="server" ErrorMessage="Please fill the value date field." SetFocusOnError="true" Display="none"></asp:RequiredFieldValidator>
                </div>


                <asp:Label ID="Label17" CssClass="col-xs-2" runat="server">Maturity Date : </asp:Label>
                <div class="col-xs-6 col-sm-3">
                    <asp:TextBox CssClass="form-control" ID="uiMaturityDate" runat="server" OnTextChanged="uiMaturityDate_TextChanged" AutoPostBack="true"></asp:TextBox>
                    <asp:RequiredFieldValidator ControlToValidate="uiMaturityDate" runat="server" ErrorMessage="Please fill the maturity date field." SetFocusOnError="true" Display="none"></asp:RequiredFieldValidator>
                </div>


                <asp:Label ID="Label19" CssClass="col-xs-2" runat="server">Terms : </asp:Label>
                <div class="col-xs-6 col-sm-3">
                    &nbsp;<asp:Label ID="lblTerms"  runat="server"></asp:Label>
                </div>

这是验证

protected void uiMaturityDate_TextChanged(object sender, EventArgs e)
    {
        try
        {
            HideError();
            if (!string.IsNullOrEmpty(uiMaturityDate.Text) && !string.IsNullOrEmpty(uiTxtValDate.Text))
            {
                if (DateTime.Parse(uiMaturityDate.Text) < DateTime.Parse(uiTxtValDate.Text))
                {
                    throw new ApplicationException("Maturity Date must be Greater Than Value Date");
                }
                else if (DateTime.Parse(uiMaturityDate.Text) > DateTime.Parse(uiTxtValDate.Text))
                {
                    TimeSpan difference = DateTime.Parse(uiMaturityDate.Text) - DateTime.Parse(uiTxtValDate.Text);
                    lblTerms.Text = (difference.Days + " days").ToString();
                }
            }
            else if (!String.IsNullOrEmpty(uiMaturityDate.Text) && (DateTime.Parse(uiMaturityDate.Text) - DateTime.Now).Days < 0)
            {
                btnAdd.Enabled = false;
                btnUpdate.Enabled = false;
                throw new ApplicationException("Maturity date must be greater than today");
            }
            else
            {
                if (Session["STATUS"] == "ADD")
                {
                    btnAdd.Enabled = true;
                }
                else if (Session["STATUS"] == "UPDATE")
                {
                    btnUpdate.Enabled = true;
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }

    protected void uiTxtValDate_TextChanged(object sender, EventArgs e)
    {
        try
        {
            HideError();
            if (!string.IsNullOrEmpty(uiMaturityDate.Text) && !string.IsNullOrEmpty(uiTxtValDate.Text))
            {
                if (DateTime.Parse(uiMaturityDate.Text) < DateTime.Parse(uiTxtValDate.Text))
                {
                    throw new ApplicationException("Maturity Date must be Greater Than Value Date");
                }
                else if (DateTime.Parse(uiMaturityDate.Text) > DateTime.Parse(uiTxtValDate.Text))
                {
                    TimeSpan difference = DateTime.Parse(uiMaturityDate.Text) - DateTime.Parse(uiTxtValDate.Text);
                    lblTerms.Text = (difference.Days + " days").ToString();
                }
            }
            else if (!String.IsNullOrEmpty(uiTxtValDate.Text) && (DateTime.Parse(uiTxtValDate.Text) - DateTime.Now).Days < 0)
            {
                btnAdd.Enabled = false;
                btnUpdate.Enabled = false;
                throw new ApplicationException("Value date must be greater than today");
            }
            else
            {
                if (Session["STATUS"] == "ADD")
                {
                    btnAdd.Enabled = true;
                }
                else if (Session["STATUS"] == "UPDATE")
                {
                    btnUpdate.Enabled = true;
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }

当我从vs 2010调试时它可以工作,但是当我从发布项目运行时,这些条款没有出现

0 个答案:

没有答案