Hi
I want to validate new records before they gets added to the grid at client-side. After I clear out the "name" field tag I get the red *. Which is perfectly fine and just what I want to do. However, when I click on "Add new record" button more than once, new empty record gets added without being validated.
What is the most clean and neat way to achieve this? Below is my code using a classic ASP coding style, so you get everything at one place.
01.
<%@ Page Language="C#" %>
02.
03.
<!DOCTYPE html>
04.
05.
<
html
>
06.
<
head
runat
=
"server"
>
07.
<
title
>[Title]</
title
>
08.
<
script
runat
=
"server"
>
09.
protected override void OnInit(EventArgs e)
10.
{
11.
this.Load += HandleLoad;
12.
this.PreLoad += HandlePreLoad;
13.
14.
base.OnInit(e);
15.
}
16.
private void HandleLoad(object sender, EventArgs e)
17.
{
18.
this.grid.DataSource = new[] { new { Id = 1, Name = "Name" } };
19.
}
20.
private void HandlePreLoad(object sender, EventArgs e)
21.
{
22.
this.grid.MasterTableView.AutoGenerateColumns = false;
23.
this.grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
24.
this.grid.MasterTableView.EditMode = GridEditMode.Batch;
25.
}
26.
</
script
>
27.
</
head
>
28.
<
body
>
29.
<
form
id
=
"form"
runat
=
"server"
>
30.
<
asp:ScriptManager
runat
=
"server"
/>
31.
<
div
style
=
"width: 25%"
>
32.
<
telerik:RadGrid
ID
=
"grid"
runat
=
"server"
>
33.
<
MasterTableView
>
34.
<
Columns
>
35.
<
telerik:GridTemplateColumn
HeaderText
=
"Name"
>
36.
<
EditItemTemplate
>
37.
<
asp:TextBox
ID
=
"name"
runat
=
"server"
/>
38.
<
asp:RequiredFieldValidator
runat
=
"server"
ControlToValidate
=
"name"
Text
=
"*"
/>
39.
</
EditItemTemplate
>
40.
<
ItemTemplate
>
41.
<%# Eval("Name") %>
42.
</
ItemTemplate
>
43.
</
telerik:GridTemplateColumn
>
44.
</
Columns
>
45.
</
MasterTableView
>
46.
</
telerik:RadGrid
>
47.
</
div
>
48.
</
form
>
49.
</
body
>
50.
</
html
>
Regrads,
Garmco ICT