In this article i will show you how you can dynamically enable or disable validator and page.isvalid using c# in asp.net.
First i will show you how you can enable the validation for all the validation in page. So here we ho.
First create a new asp.net web application. Now add a new page and add the textbox and validation controls. After adding all the controls on the page your code page will look like this.
Name
First i will show you how you can enable the validation for all the validation in page. So here we ho.
First create a new asp.net web application. Now add a new page and add the textbox and validation controls. After adding all the controls on the page your code page will look like this.
Dynamically Enable or Disable Validator and Page.IsValid Using C# In ASP.NET
Name
style="color: #FFFFCC; background-color: #FF0000" />
ControlToValidate="TextBox1" ErrorMessage="Please enter name"
style="color: #FFFFCC; background-color: #FF0000">*
Address
ControlToValidate="TextBox2" ErrorMessage="RequiredFieldValidator"
style="color: #FFFFCC; background-color: #FF0000">*
Now run the application and click on button. Validation will take place.
Now click on button
validation will take pace.
Now we will disable the validation for the page. For this come to you .cs page and add the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.CausesValidation = false;
}
protected void Button1_Click1(object sender, EventArgs e)
{
Page.Validate("ValidationSummary1");
if (Page.IsValid)
{
lblmessage.Text = "Its a server side value";
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.CausesValidation = false;
}
protected void Button1_Click1(object sender, EventArgs e)
{
Page.Validate("ValidationSummary1");
if (Page.IsValid)
{
lblmessage.Text = "Its a server side value";
}
}
}
}
in above code we have disabled the cause validation property of the page, and on button click we have we are validating the page post is valid or not.
So run the page and click on the button the page post will take place without validating page post will take place.
Tags: Asp.Net , C#.Net
No comments:
Post a Comment