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