This is a migrated thread and some comments may be shown as answers.

Client Script on Grid edit items

1 Answer 54 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Cory asked on 10 Nov 2015, 02:57 PM

Hi - I've been searching for the way to do this and haven't found it yet.

 I have a grid defined on my page in the normal fashion - with bound columns that allow editing:

 <asp:DataGrid id="dgActivityGroup" runat="server" ForeColor="Black" GridLines="Vertical" CellPadding="3"
AutoGenerateColumns="False" BackColor="White" Width="704px" BorderWidth="1px" BorderStyle="Solid"
BorderColor="Silver" Font-Names="Arial">
<FooterStyle Font-Bold="True" ForeColor="#244272" BorderColor="#B3C5E1" BackColor="#E0EEFE"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#6699CC"></SelectedItemStyle>
<EditItemStyle BackColor="#6699CC"></EditItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#244272" BorderColor="#B3C5E1" BackColor="#E0EEFE"></HeaderStyle>
<asp:BoundColumn Visible="False" DataField="ItemIndex" ReadOnly="True" HeaderText="ItemIndex"></asp:BoundColumn>
<asp:BoundColumn DataField="ActivityGroup" HeaderText="Activity Group"></asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="Description"></asp:BoundColumn>
<asp:BoundColumn DataField="ReportGroup" HeaderText="Report Group"></asp:BoundColumn>
<asp:BoundColumn DataField="TrendTotalGroup" HeaderText="Trend Total Group"></asp:BoundColumn>
<asp:BoundColumn DataField="UnitOfMeasure" HeaderText="Unit of Measure"></asp:BoundColumn>
<asp:BoundColumn DataField="SortOrder" HeaderText="Sort Order"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
<asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999"></PagerStyle>


I also have an additional INPUT field on the page that tracks if someone is making changes to the data so I can pop up an "Are you sure" message.

<INPUT id="hdnPageChange" style="WIDTH: 40px; HEIGHT: 19px" type="hidden" size="1" value="false" name="hdnPageChange" runat="server">


In the older version of the Telerik controls that I was using with VisualStudio 2003, I used to prerender event to add client script as such:

private void dgActivityGroup_PreRender(object sender, System.EventArgs e)
if (dgActivityGroup.EditItemIndex > -1)
int currentIndex = int.Parse(dgActivityGroup.Items[dgActivityGroup.EditItemIndex].Cells[CELL_ITEM_INDEX].Text);

((LinkButton)dgActivityGroup.Items[dgActivityGroup.EditItemIndex].Cells[CELL_EDIT_LINK].Controls[0]).Attributes.Add("onclick", "checkScrollPos(); hdnPageChange.value = 'false'");
((LinkButton)dgActivityGroup.Items[dgActivityGroup.EditItemIndex].Cells[CELL_EDIT_LINK].Controls[2]).Attributes.Add("onclick", "checkScrollPos(); hdnPageChange.value = 'false'");
((LinkButton)dgActivityGroup.Items[dgActivityGroup.EditItemIndex].Cells[CELL_DELETE_LINK].Controls[0]).Enabled = false;


This code worked perfectly before - when the person clicked the Edit button - it would call the client code to set the hdnPageChange.value = false.  But now in the new version of the controls, I get an error:

 Unhandled exception at line 103, column 948 in http://localhost:5040/ActivityGroup.aspx
0x800a1391 - JavaScript runtime error: 'hdnPageChange' is undefined


But hdnPageChange definitely exists... even when I do a view source on the page I can see it.  Any idea what I'm doing wrong?  Is there a better way to solve the problem with the new version of the code?




1 Answer, 1 is accepted

Sort by
Viktor Tachev
Telerik team
answered on 13 Nov 2015, 09:01 AM
Hello Cory,

From the provided markup it seems that you are not using any Telerik controls. In case you are using a standard ASP DataGrid you should refer tor the ASP.NET forums.

Viktor Tachev
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question