2
2obvious
Below is a cut-and-paste code example that runs. It demonstrates some
results which confuse me.
It uses a DataGrid to make a table with 12 rows, each containing a
TextBox and a CustomValidator. When a textbox is populated, the
validator should write out the index of the row that triggered it. And
it does--twice.
e.g. If you type something into the first row, you see "0 0." If you
type something into the first and third rows, you see "0 2 0 2." I
would only expect to see one set of results. (I only /want/ one set of
results.) Can anyone explain why I'm seeing /two/?
<%@ page language="vb" runat="server" Debug="true"%>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If ( IsPostBack ) Then
Validate()
Else
Dim numArray(12) As Integer
OurDataGrid.DataSource = numArray
OurDataGrid.DataBind()
End If
End Sub
Sub WriteIndex(source as Object, value as ServerValidateEventArgs)
Response.Write(source.Parent.Parent.ItemIndex & "<br>")
End Sub
</script>
<html><body>
<form runat="server">
<asp:Label id="OurLabel" runat="server" /><br />
<aspataGrid id="OurDataGrid"
AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:TextBox id="firstName" runat="server" />
<asp:CustomValidator id="OurCustomValidator"
ControlToValidate="firstName"
OnServerValidate="WriteIndex"
runat="server"></asp:CustomValidator>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
<p>
<asp:Button text="Submit" runat="server" />
</p>
</form>
</body></html>
results which confuse me.
It uses a DataGrid to make a table with 12 rows, each containing a
TextBox and a CustomValidator. When a textbox is populated, the
validator should write out the index of the row that triggered it. And
it does--twice.
e.g. If you type something into the first row, you see "0 0." If you
type something into the first and third rows, you see "0 2 0 2." I
would only expect to see one set of results. (I only /want/ one set of
results.) Can anyone explain why I'm seeing /two/?
<%@ page language="vb" runat="server" Debug="true"%>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If ( IsPostBack ) Then
Validate()
Else
Dim numArray(12) As Integer
OurDataGrid.DataSource = numArray
OurDataGrid.DataBind()
End If
End Sub
Sub WriteIndex(source as Object, value as ServerValidateEventArgs)
Response.Write(source.Parent.Parent.ItemIndex & "<br>")
End Sub
</script>
<html><body>
<form runat="server">
<asp:Label id="OurLabel" runat="server" /><br />
<aspataGrid id="OurDataGrid"
AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:TextBox id="firstName" runat="server" />
<asp:CustomValidator id="OurCustomValidator"
ControlToValidate="firstName"
OnServerValidate="WriteIndex"
runat="server"></asp:CustomValidator>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
<p>
<asp:Button text="Submit" runat="server" />
</p>
</form>
</body></html>