Compare Validator Disable Submit when validtion failed

Hi Dudes,

Little info about compare validator . We need to set

ContolToValidate=”IdOftheTargetTextBox”

ValidationGroup=”SetSameNameAsLike in SubmitButton”

Operator –> If we set Greater than equal means it will show error message when we enter lesser date

If u need to compare with Current Date means need to set ValueToCompare  property in page_load. Like a mentioned follow….

Aspx Side :

<asp:TextBox ID=”txtDueDate” Cs  ReadOnly=”true” runat=”server” />

<asp:CompareValidator ID=”cmpVal1″ ControlToValidate=”txtDueDate” Display=”Dynamic”  ValidationGroup=”SaveGroup” Type=”Date” Operator=”GreaterThanEqual”   SetFocusOnError=”true” BorderColor=”Red”  ErrorMessage=”Cannot be lesser than today”
ToolTip=”Date cannot be lesser than today” runat=”server”></asp:CompareValidator>

<asp:Button ID=”btnSave”   ValidationGroup=”SaveGroup” runat=”server”      Text=”Save” CssClass=”button” OnClientClick=”return validateAnalysisElements()”                                                        OnClick=”btnSave_Click” />

Script :

<script type=”text/javascript”>
function validateAnalysisElements() {
            if (Page_IsValid) {
                return true;
            }
            else {
                return false;
            }
}
</script>

Page.CS

In Page_Load  We need to set Current date to the compare validator . Then it can validate while compare

cmpVal1.ValueToCompare = DateTime.Now.ToShortDateString();

 

Advertisements

Disable Back Button of Browser

Put Following script in Masterpage. Through that u can prevent it for the whole website

<script type=”text/javascript”>
      window.location.hash = “no-back-button”;
        window.location.hash = “Again-No-back-button”; //again because google chrome don’t insert first hash into history
        window.onhashchange = function () { window.location.hash = “No-Back “; }
</script>

When you put like that In Browser Url window U can see

http://localhost:62951/Home.aspx#No-Back