473,772 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
requiredfieldva lidator 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:TemplateCo lumn HeaderText="C #">
<ItemTemplate >
<asp:TextBox Width="50" MaxLenght="5" TextMode="Singl eLine" ID="Cnumber"
runat="server" />
<asp:CustomVali dator id="CNumNotNull "
ControlToValida te="Cnumber"
Display="Static "
InitialValue=""
OnServerValidat e = "Validate"
ErrorMessage="P lease enter a C Number"
runat="server">
*
</asp:CustomValid ator>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Sel ect" ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="chkSelectIn Progress" runat="server" />
</ItemTemplate>
</asp:TemplateCol umn>

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

void Validate (object source,
System.Web.UI.W ebControls.Serv erValidateEvent Args e) {
e.IsValid = false;

DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList. Items) {
GridHolder = NewListItem.Fin dControl("InPro gressGrid") as DataGrid;
foreach (DataGridItem NewGridItem in GridHolder.Item s) {
CheckBox chkSelectInProg ress =
(CheckBox)NewGr idItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGri dItem.Cells[5].Controls[1];

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

Any suggestions?
Thanks,
Stephan.

Nov 18 '05 #1
1 3014
I can offer you a commercial solution that includes full client-side
validation support. My product, "Profession al 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 RequiredTextVal idator with the Enabler on
the CheckBox would look like:
<asp:checkbox id=checkbox1 runat=server>Ch eckMe</asp:checkbox>
<asp:textbox id=textbox1 runat=server />
<vam:RequiredTe xtValidator id=RTV1 runat=server ErrorMessage="R equired"
ControlIDToEval uate="TextBox1" >
<EnablerContain er>
<vam:CheckState Condition ControlIDToEval uate="checkbox1 " Checked=true
/>
</EnablerContaine r>
</vam:RequiredTex tValidator>

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****@PeterBlu m.com

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BC2D800A.D DD8%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
requiredfieldva lidator 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:TemplateCo lumn HeaderText="C #">
<ItemTemplate >
<asp:TextBox Width="50" MaxLenght="5" TextMode="Singl eLine" ID="Cnumber"
runat="server" />
<asp:CustomVali dator id="CNumNotNull "
ControlToValida te="Cnumber"
Display="Static "
InitialValue=""
OnServerValidat e = "Validate"
ErrorMessage="P lease enter a C Number"
runat="server">
*
</asp:CustomValid ator>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Sel ect" ItemStyle-HorizontalAlign ="Center"> <ItemTemplate >
<asp:CheckBox ID="chkSelectIn Progress" runat="server" />
</ItemTemplate>
</asp:TemplateCol umn>

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

void Validate (object source,
System.Web.UI.W ebControls.Serv erValidateEvent Args e) {
e.IsValid = false;

DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList. Items) {
GridHolder = NewListItem.Fin dControl("InPro gressGrid") as DataGrid; foreach (DataGridItem NewGridItem in GridHolder.Item s) {
CheckBox chkSelectInProg ress =
(CheckBox)NewGr idItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGri dItem.Cells[5].Controls[1];
if (chkSelectInPro gress.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
1204
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 try to reference it in my C# the control is not recognised . My code is : <asp:customvalidator ID="valCustom" runat="server" ForeColor="#FFFFFF" ControlToValidate="txtDCUG" OnServerValidate="Validate_DCUG"
2
3921
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 javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
2
5386
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 when you start typing inside a textbox, you see things that have already been typed before), then when I click off the textbox, the custom validator client side jscript does not run. I really need the custom jscript validator code to run...
1
1754
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 problem when user clicks on update in datagrid. My problem is that when I try to get customvalidation to work when user changes the value in the control, as i want this to be checked as soon as user changes the control. The custom control offers an
5
2448
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 the control in to the header section of my datalist it doesn't work, the ServerValidate event doesn't fire. I presume that I haven't wirded it up correctly.
8
7837
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 VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
0
1310
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 column in the same grid. My problem is how to determine what row the imagebutton clicked was at to retrieve a reference to the textbox I want to validate the data in. I was hoping to capture this in the Item_Command event, but the validation seem to...
3
8250
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, even if I force the customvalidator to validate by invoking its validate() method after a button is clicked: cvCustomValidator_ServerValidate(object source, system.Web.UI.WebControls.ServerValidateEventArgs args) <== doesn't get
1
1444
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 *OK' in the confirm box, he is taken to the next page. If he clicks *Cancel* in the confirm box, he stays on that page itself. I have a Web Form which houses a DataGrid. To edit the data in the DataGrid, I am using <asp:EditCommandColumn/>. To...
0
9620
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.