473,405 Members | 2,160 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,405 software developers and data experts.

Custom validator inside DataGrid

Hi,
I need to validate a text box in a datagrid nested inside a datalist. All I
need is to validate that any text is entered in the textbox. However, a
requiredfieldvalidator would not do because I want to perform the validation
only on the datagrid rows where a check box is checked.

Part of the datagrid:

<asp:TemplateColumn HeaderText="C #">
<ItemTemplate>
<asp:TextBox Width="50" MaxLenght="5" TextMode="SingleLine" ID="Cnumber"
runat="server" />
<asp:CustomValidator id="CNumNotNull"
ControlToValidate="Cnumber"
Display="Static"
InitialValue=""
OnServerValidate = "Validate"
ErrorMessage="Please enter a C Number"
runat="server">
*
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelectInProgress" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>

However, the "Validate" script doesn't appear to run:

void Validate (object source,
System.Web.UI.WebControls.ServerValidateEventArgs e) {
e.IsValid = false;

DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList.Items) {
GridHolder = NewListItem.FindControl("InProgressGrid") as DataGrid;
foreach (DataGridItem NewGridItem in GridHolder.Items) {
CheckBox chkSelectInProgress =
(CheckBox)NewGridItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGridItem.Cells[5].Controls[1];

if (chkSelectInProgress.Checked == true) {
String Test = e.Value;
if (Test.Length > 0) {
e.IsValid = true;
}
}
}
}
}

Any suggestions?
Thanks,
Stephan.

Nov 18 '05 #1
1 2982
I can offer you a commercial solution that includes full client-side
validation support. My product, "Professional Validation And More", is a
replacement to Microsoft's validators that overcomes its many limitations.
What you've asked for is one of the most important limitations: the ability
to have a validator disable itself when some other condition (like a
checkbox) isn't right. All the validators in Professional Validation And
More include the Enabler property, where you define the condition.

Here's what the ASP.NET text of my RequiredTextValidator with the Enabler on
the CheckBox would look like:
<asp:checkbox id=checkbox1 runat=server>CheckMe</asp:checkbox>
<asp:textbox id=textbox1 runat=server />
<vam:RequiredTextValidator id=RTV1 runat=server ErrorMessage="Required"
ControlIDToEvaluate="TextBox1">
<EnablerContainer>
<vam:CheckStateCondition ControlIDToEvaluate="checkbox1" Checked=true
/>
</EnablerContainer>
</vam:RequiredTextValidator>

Aside from the Enabler, you get client-side validation on many more
browsers, 17 validators, and Validation Groups. Learn more at
http://www.peterblum.com/vam/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC2D800A.DDD8%sb***@niaid.nih.gov...
Hi,
I need to validate a text box in a datagrid nested inside a datalist. All I need is to validate that any text is entered in the textbox. However, a
requiredfieldvalidator would not do because I want to perform the validation only on the datagrid rows where a check box is checked.

Part of the datagrid:

<asp:TemplateColumn HeaderText="C #">
<ItemTemplate>
<asp:TextBox Width="50" MaxLenght="5" TextMode="SingleLine" ID="Cnumber"
runat="server" />
<asp:CustomValidator id="CNumNotNull"
ControlToValidate="Cnumber"
Display="Static"
InitialValue=""
OnServerValidate = "Validate"
ErrorMessage="Please enter a C Number"
runat="server">
*
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center"> <ItemTemplate>
<asp:CheckBox ID="chkSelectInProgress" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>

However, the "Validate" script doesn't appear to run:

void Validate (object source,
System.Web.UI.WebControls.ServerValidateEventArgs e) {
e.IsValid = false;

DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList.Items) {
GridHolder = NewListItem.FindControl("InProgressGrid") as DataGrid; foreach (DataGridItem NewGridItem in GridHolder.Items) {
CheckBox chkSelectInProgress =
(CheckBox)NewGridItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGridItem.Cells[5].Controls[1];
if (chkSelectInProgress.Checked == true) {
String Test = e.Value;
if (Test.Length > 0) {
e.IsValid = true;
}
}
}
}
}

Any suggestions?
Thanks,
Stephan.

Nov 18 '05 #2

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

Similar topics

0
by: Mike P | last post by:
Is it possible to use custom validators when editing a datagrid? I'm asking this because I am trying to use a custom validator to validate a control which is in an <edititemtemplate> tag and when I...
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
2
by: Dot net work | last post by:
Hello. If I use an asp.net custom validator control to validate a textbox, what I find is that if I enter in some text that I have already entered and validated in a previous session (you know...
1
by: philipl | last post by:
hi, i have a datagrid which display custom controls when user clicks edit, changing data. I am using customvalidator to validate this control. I can get validation of user input to work no...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
0
by: Niclas | last post by:
Hi, I would like to use the custom validator control to validate a textbox in a Item template within a datagrid. The post is done by the user clicking a ImageButton within another Template...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
1
by: rn5a | last post by:
I have created a custom server control which is actually a Button clicking which prompts a user with a JavaScript confirm message asking him whether he would like to proceed or not. If he clicks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.