473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem With Custom Validation In a Details View

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:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="PriceRangeID"

DataSourceID="PriceRangeDataSource" DefaultMode="Insert" >

<Fields>

<asp:TemplateField HeaderText="Min" SortExpression="Min">

<EditItemTemplate>

&nbsp;<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>&nbsp;

</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>&nbsp;

</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:DetailsView>

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;

}
}
Aug 8 '06 #1
1 3489
Any help here?

"Microsoft News Group" <mf****@cvmediaonline.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
>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:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="PriceRangeID"

DataSourceID="PriceRangeDataSource" DefaultMode="Insert" >

<Fields>

<asp:TemplateField HeaderText="Min" SortExpression="Min">

<EditItemTemplate>

&nbsp;<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>&nbsp;

</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>&nbsp;

</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:DetailsView>

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;

}
}


Aug 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
1
by: Serdar Kalaycý | last post by:
I added a custom validator and added some code to its ServerValidate event but when a data which is not accepted is entered, it gives the warning as it should do, but doesn't stop the execution of...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
0
by: Rene Aichinger | last post by:
Hi, I've created a server control (it inherits from WebControl) wich has a property of genertic collection type. The type of the generic collection is NavigationItem, a little class I've...
0
by: A.J. van der Burg | last post by:
Hi all, I have a serious problem with asp.net validation: I developed a custom validation summary control, which will lookup error messages from an external source based on the...
7
by: awyl | last post by:
I tried to use validation in asp.net 2.0 with the following code. <%@ Page Language="c#" %> <html> <body> <form runat="server"> <asp:TextBox ID="abc" runat="server"> </asp:TextBox>...
6
by: BookerW | last post by:
Ok interesting, on my local machine And i did not do a good job of keeping track of the exact order.... but on my local machine in which i have vis studio 2003 installed and IIS for win XP,...
1
by: Tarun Mistry | last post by:
Hi there everyone, I have a page containing dynamic user controls. The main page contains a custom validator that checks the dynamic user controls, this works fine. However, I only want the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.