M
Microsoft News Group
I am trying to validate two textboxes as their values are the same, or both
are null do not insert the data. I do not just want one to try to be null,
I want both of them, so the requirevalidator will not work because I want
both to be null or equal. I am assuming using the Custom Validator. Here
is my DetailsViewCode:
<asp
etailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="PriceRangeID"
DataSourceID="PriceRangeDataSource" DefaultMode="Insert" >
<Fields>
<asp:TemplateField HeaderText="Min" SortExpression="Min">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Min")
%>'></asp:TextBox>
<asp:CustomValidator ID="EmptyInsertSpacer" runat="server"
OnServerValidate="EmptyInsertSpacer_ServerValidate"
ControlToValidate="TextBox1"
ValidationGroup="InsertValidatorGroup"></asp:CustomValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="MinTextBox" runat="server" Text='<%# Bind("Min")
%>'></asp:TextBox>
<asp:CompareValidator ID="MinValidator" runat="server"
ControlToValidate="MinTextBox"
ErrorMessage="Minimum value is not a currency value!" Type="Currency"
ValidationGroup="InsertValidatorGroup"
Operator="DataTypeCheck">*</asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Min") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Max" SortExpression="Max">
<EditItemTemplate>
<asp:TextBox ID="MaxInsertTextBox" runat="server" Text='<%# Bind("Max")
%>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="MaxTextBox" runat="server" Text='<%# Bind("Max")
%>'></asp:TextBox>
<asp:CompareValidator ID="MaxValidator" runat="server"
ControlToValidate="MaxTextBox"
ErrorMessage="Maximum value entered is not a curreny value!"
Operator="DataTypeCheck"
Type="Currency"
ValidationGroup="InsertValidatorGroup">*</asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Max") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True"
ValidationGroup="InsertValidatorGroup" />
</Fields>
</asp
etailsView>
Here is my custom validator code which is not working. Any help would be
greatly appreciated.
protected void EmptyInsertSpacer_ServerValidate(object source,
ServerValidateEventArgs args)
{
DetailsViewRow rowmin = DetailsView1.Rows[1];
string min = rowmin.Cells[0].Text;
DetailsViewRow rowmax = DetailsView1.Rows[1];
string max = rowmax.Cells[1].Text;
if (min == max)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
are null do not insert the data. I do not just want one to try to be null,
I want both of them, so the requirevalidator will not work because I want
both to be null or equal. I am assuming using the Custom Validator. Here
is my DetailsViewCode:
<asp
DataKeyNames="PriceRangeID"
DataSourceID="PriceRangeDataSource" DefaultMode="Insert" >
<Fields>
<asp:TemplateField HeaderText="Min" SortExpression="Min">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Min")
%>'></asp:TextBox>
<asp:CustomValidator ID="EmptyInsertSpacer" runat="server"
OnServerValidate="EmptyInsertSpacer_ServerValidate"
ControlToValidate="TextBox1"
ValidationGroup="InsertValidatorGroup"></asp:CustomValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="MinTextBox" runat="server" Text='<%# Bind("Min")
%>'></asp:TextBox>
<asp:CompareValidator ID="MinValidator" runat="server"
ControlToValidate="MinTextBox"
ErrorMessage="Minimum value is not a currency value!" Type="Currency"
ValidationGroup="InsertValidatorGroup"
Operator="DataTypeCheck">*</asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Min") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Max" SortExpression="Max">
<EditItemTemplate>
<asp:TextBox ID="MaxInsertTextBox" runat="server" Text='<%# Bind("Max")
%>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="MaxTextBox" runat="server" Text='<%# Bind("Max")
%>'></asp:TextBox>
<asp:CompareValidator ID="MaxValidator" runat="server"
ControlToValidate="MaxTextBox"
ErrorMessage="Maximum value entered is not a curreny value!"
Operator="DataTypeCheck"
Type="Currency"
ValidationGroup="InsertValidatorGroup">*</asp:CompareValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Max") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True"
ValidationGroup="InsertValidatorGroup" />
</Fields>
</asp
Here is my custom validator code which is not working. Any help would be
greatly appreciated.
protected void EmptyInsertSpacer_ServerValidate(object source,
ServerValidateEventArgs args)
{
DetailsViewRow rowmin = DetailsView1.Rows[1];
string min = rowmin.Cells[0].Text;
DetailsViewRow rowmax = DetailsView1.Rows[1];
string max = rowmax.Cells[1].Text;
if (min == max)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}