G
Guest
Ok, so I'm working through examples in the apress book "Pro ASP.NET 2.0 in C#
2005". The Validation groups example doesn't work the way I thought it
should. It consists of 2 textboxes and 2 buttons and 2 required field
validators. One set of controls is set to validation group "G1" and the
other set to "G2". There is also a label to display what happens on the
server.
The example appears to work flawlessly at the browser but results at the
server vary. Specifically, leave the first textbox empty and enter text in
the 2nd textbox (group "G2" controls) and click it's Validate button. The
page posts back and the server reports that both groups evaluate to false. I
had expected The "G2" contol to evaluate to true. Am I missing somrthing
here? See below for the HTML and code behind.
Bill
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="10ValidationGroups.aspx.cs"
Inherits="Ch04ServerControls_10ValidationGroups" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validation Groups</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-size: 16pt; color: #0000cc">
Pro ASP.NET 2.0 in C#<br />
Chapter 4, Page 144<br />
<hr style="color: #ff0099; height: 5px" />
Web Controls - Validation Groups
<br />
<asp:HyperLink ID="HyperLink1" runat="server" font-size="10pt"
NavigateUrl="~/Default.aspx">[Home]</asp:HyperLink>
<br />
<br />
</div>
<div>
<aspanel ID="Panel1" runat="server" Height="67px" Width="281px">
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="G1"
Width="229px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="*Required."
Width="185px" ControlToValidate="TextBox1"
ValidationGroup="G1"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server" Text="Validate Group 1"
ValidationGroup="G1"
Width="139px" OnClick="ValidatAll_Click" /></aspanel>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<aspanel ID="Panel2" runat="server" Height="67px" Width="281px">
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="G2"
Width="230px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="*Required."
Width="186px" ControlToValidate="TextBox2"
ValidationGroup="G2"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button2" runat="server" Text="Validate Group 2"
ValidationGroup="G2"
Width="139px" OnClick="ValidatAll_Click" /></aspanel>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Ch04ServerControls_10ValidationGroups :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ValidatAll_Click(object sender, EventArgs e)
{
Label1.Text = "Valid: " + Page.IsValid.ToString();
Page.Validate("G1");
Label1.Text += "<br/>Group 1 Valid: " + Page.IsValid.ToString();
Page.Validate("G2");
Label1.Text += "<br/>Group 2 Valid: " + Page.IsValid.ToString();
}
}
2005". The Validation groups example doesn't work the way I thought it
should. It consists of 2 textboxes and 2 buttons and 2 required field
validators. One set of controls is set to validation group "G1" and the
other set to "G2". There is also a label to display what happens on the
server.
The example appears to work flawlessly at the browser but results at the
server vary. Specifically, leave the first textbox empty and enter text in
the 2nd textbox (group "G2" controls) and click it's Validate button. The
page posts back and the server reports that both groups evaluate to false. I
had expected The "G2" contol to evaluate to true. Am I missing somrthing
here? See below for the HTML and code behind.
Bill
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="10ValidationGroups.aspx.cs"
Inherits="Ch04ServerControls_10ValidationGroups" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validation Groups</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-size: 16pt; color: #0000cc">
Pro ASP.NET 2.0 in C#<br />
Chapter 4, Page 144<br />
<hr style="color: #ff0099; height: 5px" />
Web Controls - Validation Groups
<br />
<asp:HyperLink ID="HyperLink1" runat="server" font-size="10pt"
NavigateUrl="~/Default.aspx">[Home]</asp:HyperLink>
<br />
<br />
</div>
<div>
<aspanel ID="Panel1" runat="server" Height="67px" Width="281px">
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="G1"
Width="229px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="*Required."
Width="185px" ControlToValidate="TextBox1"
ValidationGroup="G1"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server" Text="Validate Group 1"
ValidationGroup="G1"
Width="139px" OnClick="ValidatAll_Click" /></aspanel>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<aspanel ID="Panel2" runat="server" Height="67px" Width="281px">
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="G2"
Width="230px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="*Required."
Width="186px" ControlToValidate="TextBox2"
ValidationGroup="G2"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button2" runat="server" Text="Validate Group 2"
ValidationGroup="G2"
Width="139px" OnClick="ValidatAll_Click" /></aspanel>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Ch04ServerControls_10ValidationGroups :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ValidatAll_Click(object sender, EventArgs e)
{
Label1.Text = "Valid: " + Page.IsValid.ToString();
Page.Validate("G1");
Label1.Text += "<br/>Group 1 Valid: " + Page.IsValid.ToString();
Page.Validate("G2");
Label1.Text += "<br/>Group 2 Valid: " + Page.IsValid.ToString();
}
}