Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

thanks for visiting , this is my initial question that lead me to modify the behavior of AJAX MaskedEditValidator - isValidEmpty attribute.

when you try to cancel the interaction with a form , being a form that one of its elemets (say the first textbox) is set to "required" . in that case , the validator will not let you do anything unless you first type a valid value in the target text box .

you have no choice other than to fill the field that you set focus to as required.

till then the user is disabled rather than the UI (:.

so I came up with a solution, though I think should be optimized so it would suit any target TextBox (actually target is MaskedEditValidator-ID and the text box is only the referencing entity) in this case .

and also the code is far from being as elegant and clean so i could proudly share it with everyone

  • MaskedEditExtender

      <cc1:MaskedEditExtender enabled="true" MaskType="Date" 
           ID="insertDate_MaskedEditExtender" runat="server"
           TargetControlID="TBXinsertDate"  InputDirection="LeftToRight"
           CultureName="en-GB" 
           UserDateFormat="None" Mask="99/99/9999" MessageValidatorTip="true"
           OnFocusCssClass="maskedFocus" ErrorTooltipEnabled="true"
           ErrorTooltipCssClass="toolTipForInvalid">
    
      </cc1:MaskedEditExtender>
    
  • MaskedEditValidator

      <cc1:MaskedEditValidator Enabled="false" IsValidEmpty="false"
           ID="insertDate_MskValidator" 
           ControlExtender="insertDate_MaskedEditExtender" 
           ControlToValidate="TBXinsertDate" runat="server"
           InvalidValueBlurredMessage="invalid date" 
           EmptyValueBlurredText="requierd fileld"  
           ErrorMessage="Error" 
           MaximumValue="01/01/2015" MinimumValue="01/01/2008"
           MinimumValueBlurredText="please enter year above 2008"
           MaximumValueBlurredMessage="max year value is 2015"
           CssClass="dateInValid">
       </cc1:MaskedEditValidator>
    
  • default state of validator

    Enabled = false : i am enabling it later on via onClick button event from code behind as follows

    insertDate_MskValidator.Enabled = true;

so the sequence is :

stage 1 - validator-enabled = false //when form is hidden

stage 2 - validator-enabled = true //when form is visible

stage 3 options:

cancel / submit

submit: will be available if form is valid

cancel: is no option if you step in one of text box leaving it empty .

and this is my solution :

JavaScript

//delay execution

function setTDisableValidation() {
         setTimeout('disableValidation()', 3500);
     }

//execute modification

    function disableValidation() {
             var myVal = document.getElementById('insertDate_MskValidator');
             myVal.disabled = true;
             myVal.ValidEmpty = true;
    }

ASPX

<body>
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     <asp:TextBox ID="TBXinsertDate" runat="server" 
          ToolTip="insert date" Width="76px" 
          onblur="setTDisableValidation();">
     </asp:TextBox>

CSS

.WaterMarkedTextBox
    {
        height: 16px;
        width: 80px;
        padding: 2px 2 2 2px;
        border: 1px solid #BEBEBE;
        background-color: #F0F8FF;
        color: gray;
        font-size: 8pt;
        text-align: center;
    }

    .NormalTextBox
    {
        height: 16px;
        width: 168px;
    }
   .greytext
   {
    color:red;
   }
   .maskedFocus
   {
    color:blue;
   }
   .dateValid
   {
   font-size:10px; color:black; 
   }
   .dateInValid
   {
              font-size:10px; color:red;display:inline-block;
   }
    .MaskedEditError
    {
                      font-size:10px; color:red;display:inline;
    }
    .toolTipForInvalid
    {
        font-size:10px; color:red; background-color:Yellow
    }
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.