Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Custom validator inside DataGrid

Reply
Thread Tools

Custom validator inside DataGrid

 
 
Stephan Bour
Guest
Posts: n/a
 
      01-16-2004
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.

 
Reply With Quote
 
 
 
 
Peter Blum
Guest
Posts: n/a
 
      01-16-2004
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: http://www.velocityreviews.com/forums/(E-Mail Removed)

"Stephan Bour" <(E-Mail Removed)> wrote in message
news:BC2D800A.DDD8%(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts Validator - creditCard validator smrimell@gmail.com Java 4 02-13-2007 08:32 PM
ClientValidationFunction function for a custom validator inside a repeater (ASPNET) Radu Javascript 0 01-26-2007 05:12 PM
Custom Validator inside datagrid Niclas ASP .Net 0 01-03-2006 09:37 PM
Re: custom validator controls within a datagrid zlusca@gmail.com ASP .Net 0 12-28-2004 07:13 PM
How to get custom control to work with custom validator Scott Yenor ASP .Net Web Controls 0 01-27-2004 12:37 AM



Advertisments