Showing posts with label Validation Summary. Show all posts
Showing posts with label Validation Summary. Show all posts

Tuesday, January 07, 2014

How to hide Validation controls from JavaScript in .NET?

Here is how you can hide validation summary using the below JavaScript.  Call this in your aspx page. This should do trick for you.

// Hiding all validation contorls  
for (i = 0; i < Page_Validators.length; i++) {
ValidatorEnable(Page_Validators[i], false)
}


It works in IE and Mozilla. Hope this helps

Thursday, October 24, 2013

How to hide Validation Summary from JavaScript in .NET?

Here is how you can hide validation summary using the below JavaScript.  Call this in your aspx page. This should do trick for you.

function HideValidationSummary(){

if (typeof(Page_ValidationSummaries)!= "undefined"){ //hide the validation summaries
for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
summary = Page_ValidationSummaries[sums];
summary.style.display = "none";
}
}

}

It works in IE and Mozilla. Hope this helps

 

Sunday, November 13, 2011

Validators Control to allow only Integers

Here are few different ways you can use native .NET validation controls to validate to allow only integers. We can do it in two ways one by using regular expression and one with compare validators

Method 1: Compare Validator
<asp:TextBox ID="NewMobileTextBox" runat="server" Width="280px" autocomplete="off"
CssClass="signuptxtbox" ></asp:TextBox>
<asp:RequiredFieldValidator ID="NewMobileRequired" runat="server" ControlToValidate="NewMobileTextBox"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="New Mobile is required." ToolTip="New Mobile is required." ValidationGroup="ChangeNewMobileValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="NewMobileCompare" runat="server" ControlToValidate="NewMobileTextBox" CssClass="failureNotification" Display="Dynamic" Operator="DataTypeCheck" ErrorMessage="Mobile Number should be numeric only." ValidationGroup="ChangeNewMobileValidationGroup" Type="Integer">*</asp:CompareValidator>


Method 2: Regular Expression Validator

<asp:TextBox ID="NewMobileTextBox" runat="server" Width="280px" autocomplete="off"
CssClass="signuptxtbox" ></asp:TextBox><asp:RequiredFieldValidator ID="NewMobileRequired" runat="server" ControlToValidate="NewMobileTextBox"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="New Mobile is required." ToolTip="New Mobile is required." ValidationGroup="ChangeNewMobileValidationGroup">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="mobileRGEX" runat="server"
ControlToValidate="NewMobileTextBox" CssClass="failureNotification"
ErrorMessage="Please Enter Only Numbers" ValidationExpression="^\d+$"
ValidationGroup="ChangeNewMobileValidationGroup"></asp:RegularExpressionValidator>

Saturday, May 28, 2011

How to Add validations controls Programmatically

I was looking for some server side validation message which can done without posting back to server. I tried doing javascript and writing that script to literal control and I have been thinking of doing a better way. But here is the cool way to do this.

// Dynamically adding Validation control
RequiredFieldValidator Validator = new RequiredFieldValidator();
Validator.ErrorMessage = "No data to download for your request.";
// Validation group must be specified as to which group you need to bind
Validator.ValidationGroup = "Group1";
Validator.IsValid = false;
Validator.Visible = false;
Page.Form.Controls.Add(Validator);

All you need to do is Depending on your need you need to change message and validation group. We need to set up validation group properly.


Happy coding Smile