I need to do a validation on start date and end date with javascript

0

I need to validate the start date and end date ... So the end date can not be less than the start date, but since I started messing with javascript less than two weeks ago I'm knocking a little. It would be this case below: Both for DataInicioCurso and DataFimCurso and DataInicioDisciplina and DataFimDisciplina .

Would you like to do a validation here? Thank you!

function PreencherDadosTurma(data) {

    var turma = data;

    turma.IdInstituicaoDeEnsino = jq.IdInstituicaoDeEnsino.val();
    turma.InstituicaoDeEnsino.IdRedeOfertante = jq.idRedeOfertante.val();
    turma.IdCurso = jq.IdCurso.val();
    turma.Descricao = jq.Descricao.val();
    turma.QtdEstudante = jq.QtdEstudante.val().ToInt32();
    turma.DataInicioCurso = jq.DataInicioCurso.val();
    turma.DataFimCurso = jq.DataFimCurso.val();
    turma.DataInicioDisciplina = jq.DataInicioDisciplina.val();
    turma.DataFimDisciplina = jq.DataFimDisciplina.val();
    turma.EmpreendedorismoAplicado = jq.EmpreendedorismoAplicadoSim.prop('checked') ? jq.EmpreendedorismoAplicadoSim.val() : jq.EmpreendedorismoAplicadoNao.val();
    turma.IdTurma = jq.IdTurma.val().ToInt32();

    return turma;
}
    
asked by anonymous 10.12.2015 / 15:01

1 answer

1

So I'm using the components called CustomValidator and UpdatePanel, remembering that you have some rules to insert UpdatePanel, if you need more details just ask: WebForm1.aspx:

<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >

    <ContentTemplate>
        <asp:TextBox runat="server" AutoPostBack ="true" ID="dataini"></asp:TextBox>
        <asp:TextBox runat="server" AutoPostBack ="true" ID="datafim" OnTextChanged="datafim_TextChanged"></asp:TextBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"  OnServerValidate="CustomValidator1_ServerValidate" ></asp:CustomValidator>
     </ContentTemplate>   

   </asp:UpdatePanel>
</div>

here is no behind: WebForm1.aspx.cs

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        DateTime dtini = Convert.ToDateTime(dataini.Text);
        DateTime dtfim = Convert.ToDateTime(datafim.Text);
        if (dtini < dtfim)
        {
            CustomValidator1.Text = "Correto";
            CustomValidator1.IsValid = true;

        }
        else
        {
            CustomValidator1.IsValid = false;
            CustomValidator1.Text = "Incorreto";
        }
    }

    protected void datafim_TextChanged(object sender, EventArgs e)
    {
        ServerValidateEventArgs svea = new ServerValidateEventArgs("",true);
        CustomValidator1_ServerValidate(sender,svea);
    }
    
11.12.2015 / 16:27