WebControl input text mask

0

I created a UserControl called UclDataVigencia very simple. Only one label and two input texts that will be responsible for receiving a start date and an end date. I would like to apply a mask to the date of type dd / mm / yyyy. I tried using jQuery MaskInput, but to no avail. I found this link , but I did not succeed, follow the UclDataVigencia_PortalTributario.ascx code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UclDataVigencia_PortalTributario.ascx.cs" Inherits="Web.Seguranca.UserControls.UclDataVigencia_PortalTributario" %>

<asp:Label ID="lb_msg" runat="server" Font-Bold="true">Data de Vigência (Mensagem de Observação)</asp:Label>

<asp:Label ID="lb_dataInicio" runat="server" Font-Bold="true">Data Início:</asp:Label><br />

<asp:TextBox ID="txt_dataInicio" runat="server" ToolTip="dd/mm/aaaa" Width="25%" CssClass="form-control" Enabled="true" ></asp:TextBox><br />

<asp:Label ID="lb_dataFim" runat="server" Font-Bold="true">Data Fim:</asp:Label><br />

<asp:TextBox ID="txt_dataFim" runat="server" ToolTip="dd/mm/aaaa" Width="25%" CssClass="form-control" Enabled="true"></asp:TextBox>
    
asked by anonymous 23.02.2018 / 20:43

1 answer

0

You could use javascript example:

<script language="JavaScript" type="text/javascript">
   function mascaraData(campoData){
              var data = campoData.value;
              if (data.length == 2){
                  data = data + '/';
                  document.forms[0].data.value = data;
      return true;              
              }
              if (data.length == 5){
                  data = data + '/';
                  document.forms[0].data.value = data;
                  return true;
              }
         }
</script>

Refer to your TextBox as follows:

<asp:TextBox ID="txt_dataInicio" runat="server"
ToolTip="dd/mm/aaaa" Width="25%"
CssClass="form-control" Enabled="true"
OnKeyUp="mascaraData(this);" maxlength="10">
</asp:TextBox><br />
    
24.02.2018 / 01:01