Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

I got an email asking about simulating ValidationGroup business case in ASP.NET 1.X.

 

Was not sure how many ways are there to simulate that behavior in ASP.NET 1.X. But I have given one simple and easy solution to him. In case if any one of you needs it, here is the source code for it! (A Very simple and self explanatory example)

**************
<%@ Page language="c#" %>
<
script language="c#" runat="server">
private
void Page_Load(object sender, System.EventArgs e)
{
   
// If it's 2.0, we can use OnClientClick for client side funciton calls!!   

   Button1.Attributes.Add("onclick","enableGroupOne();");
   Button2.Attributes.Add("onclick","enableGroupTwo();");
}

private void B1(object sender, System.EventArgs e)
{
   //two.IsValid=true;
   
lblResult.Text = "Group ONE Textbox One value is: " + txtGrpOne.Text;
}

private void B2(object sender, System.EventArgs e)
{
   //one.IsValid=true;
   
lblResult.Text = "Group TWO Textbox One value is: " + txtGrpTwo.Text;
}

</script>
<
HTML>
<HEAD>
   
<title>ValidationGroup Simulation using ASP.NET 1.X from w3coder</title>
</HEAD>
<body>
   
<form id="Form1" method="post" runat="server">
   
<h3>ValidationGroup Simulation using ASP.NET 1.X</h3><br><br>

      Group One Textbox:
      
<asp:TextBox id="txtGrpOne" runat="server"></asp:TextBox>    
      <
asp:RequiredFieldValidator id="one" runat="server" ControlToValidate="txtGrpOne" ErrorMessage="Button ONE is Clicked, Hence this is required"></asp:RequiredFieldValidator> <br>
<asp:Button id="Button1" runat="server" Text="Validate Group One" onClick="B1"></asp:Button> <br>
<br><br>

   Group Two Textbox:
   
<asp:TextBox id="txtGrpTwo" runat="server"></asp:TextBox>    
   <
asp:RequiredFieldValidator id="two" runat="server" ControlToValidate="txtGrpTwo" ErrorMessage="Button TWO is Clicked, Hence this is required"></asp:RequiredFieldValidator> <br>
   
<asp:Button id="Button2" runat="server" Text="Validate Group Two" onClick="B2"></asp:Button> <br>
<br><br>
   
<asp:Label id="lblResult" runat="server" ></asp:Label>
   
<br>
</form>

<script language="javascript">
// Disable all Validation cointrols using this!
// As it has to run first did not made as function, but you can make it as function and call it on form load client side event..
//function disableScriptfunction()
// {
for(i=0;i< Page_Validators.length;i++)
{
ValidatorEnable(Page_Validators[i], false);
}
// }
// end of the Disable funciton

// Making only Group ONE is Enable for Validation and Disable other validation controls.
function enableGroupOne()
{
   for(i=0;i< Page_Validators.length;i++)
   {
      ValidatorEnable(Page_Validators[i],
false);
   }
 ValidatorEnable(one,
true);
}

// Making only Group TWO is Enable for Validation and Disable other validation controls.
function enableGroupTwo()
{
for(i=0;i< Page_Validators.length;i++)
  {
     ValidatorEnable(Page_Validators[i],
false);
   
}
ValidatorEnable(two,
true);
 }
</script>
</body>
</
HTML>

**************

The code is very self explanatory! We could do it in many ways, but this is one way, if you have a time, you could write your own generalized module for simulating this and to make more generalized for using in a big project. Take it away and use it as you like J

Published Sunday, December 5, 2004 11:18 PM by SreedharK

Comments

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Thursday, August 9, 2007 5:43 AM by Kathryn

It's worth mentioning that if you are using Validation Summaries, you need to add one for each ValidationGroup you're using.

I guess it's not that difficult to figure out, but it had me going for a few minutes.

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, August 21, 2007 8:50 AM by dd

how2dotnet.blogspot.com

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Wednesday, November 28, 2007 8:55 AM by Niraj

ValidatorEnable not worked in FireFox.

Can you give me solution for that.

Thanking You,

Niraj

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Sunday, July 31, 2011 4:11 PM by zaanstreek

Zaandam is in 1811 ontstaan door samenvoeging van de plaatsen Oostzaandam, dat deel uit maakte van de gemeente Oostzaan, en Westzaandam, dat deel uitmaakte van de Banne Westzaan.

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Monday, August 1, 2011 8:20 AM by Westknol

West-Knollendam (officiële spelling) of Westknollendam is een dorp in de gemeente Zaanstad,

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, August 2, 2011 4:43 PM by Assendelft

Assendelft is een van oorsprong lintdorp tussen 8 en 10 kilometer in de provincie Noord-Holland. Assendelft loopt van Krommenie tot aan het Noordzeekanaal. Het lintdorp Assendelft is van oorsprong

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, December 4, 2012 1:17 AM by Paige

I think that is among the such a lot vital information for me.

And i am satisfied reading your article.

But wanna observation on few normal things,

The website style is ideal, the articles is actually great :

D. Excellent job, cheers

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, December 4, 2012 2:12 AM by Flanigan

Woah! I'm really loving the template/theme of this website. It's simple, yet

effective. A lot of times it's difficult to get that "perfect balance" between superb usability and visual appeal. I must say you have done a fantastic job with this. In addition, the blog loads extremely fast for me on Chrome. Excellent Blog!

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, December 4, 2012 2:38 AM by Schaeffer

Just want to say your article is as astonishing.

The clearness in your post is just spectacular and i can assume you are a professional

on this subject. Well along with your permission allow me to snatch your feed to keep

up to date with approaching post. Thanks one million and please continue

the gratifying work.

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Tuesday, December 4, 2012 7:00 AM by Duvall

Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something.

I think that you can do with a few pics to drive the message home a little bit,

but instead of that, this is excellent blog.

An excellent read. I'll definitely be back.

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Saturday, April 6, 2013 3:19 PM by Dyer

Since the admin of this web site is working, no hesitation very quickly it will be well-known, due to its

quality contents.

# re: Simulating ValidationGroup (of ASP.NET 2.0) feature in ASP.NET 1.X

Monday, April 8, 2013 9:47 PM by Mcconnell

I'm gone to inform my little brother, that he should also visit this web site on regular basis to take updated from newest news update.