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

Accessing New Values on Client on Insert

1 Answer 55 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Elliott asked on 26 May 2010, 09:49 PM
I am trying to hook a simple javascript function to update and insert link buttons on a radgrid
The Update is done - adding an attribute to the appropriate link button on the ItemDataBound event handler
the Insert button has me stumped
I am running VS 2010, .NET 4.0 and the code behind, as you can see, is VB
on Windows XP IE 8
anyway, appropriate code

<script type="text/javascript" language="javascript" >
    function ValidateRow(rowIndex) {
        var theGrid = $find("<%=rgDealerMaintenance.ClientID%>");
        var oneRow = null;
        if (rowIndex > -1) {
        oneRow = theGrid.get_masterTableView().get_dataItems()[rowIndex].get_element();
     // hard coded cell locations
        for (j = 0; j < oneRow.cells[0].childNodes.length; j++) {
            var FirstName = oneRow.cells[0].childNodes[j].value;
        for (j = 0; j < oneRow.cells[1].childNodes.length; j++) {
            var LastName = oneRow.cells[1].childNodes[j].value;
        if (FirstName == '' || LastName == '') {
            alert('Please enter both a first name and a last name');
            return false;
        return true;
the grid
    <telerik:RadGrid ID="rgDealerMaintenance" AutoGenerateColumns="False"
        AllowAutomaticInserts="True" GridLines="None" ShowFooter="true" runat="server" >
    <MasterTableView CommandItemDisplay="Bottom" EditMode="InPlace" DataKeyNames="RegistrationID" HeaderStyle-CssClass="body_text_black_BOLD">
    <CommandItemSettings AddNewRecordImageUrl="Images/AddRecord.gif" AddNewRecordText="Add New" />
        <telerik:GridBoundColumn DataField="RegistrationID" Visible="false" />
        <telerik:GridBoundColumn UniqueName="txtFirstName" DataField="FirstName" HeaderText="First Name">
        <telerik:GridBoundColumn UniqueName="txtLastName" DataField="LastName" HeaderText="Last Name">

        <telerik:GridEditCommandColumn EditText="Edit" UniqueName="EditCommandColumn" UpdateText="Update" CancelText="Cancel" HeaderText="Edit">
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" HeaderText="Delete">

in the code behind
    Protected Sub rgDealerMaintenance_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgDealerMaintenance.ItemDataBound
        Dim gdItem As GridDataItem = Nothing
        Dim geItem As GridEditableItem = Nothing
        Dim btnDelete, btnUpdate As LinkButton
        Dim RowIndex As Integer
        If TypeOf e.Item Is GridDataItem Then
            gdItem = DirectCast(e.Item, GridDataItem)
            ' hard-coded location!
            btnDelete = DirectCast(gdItem.Cells(9).Controls(0), LinkButton)
            btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")
        End If
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
            geItem = DirectCast(e.Item, GridEditableItem)
            btnUpdate = DirectCast(geItem.Cells(8).Controls(0), LinkButton)
            RowIndex = e.Item.ItemIndex
        SetLinkButtonClickEvent(btnUpdate, RowIndex)
        End If
    End Sub

    Private Sub SetLinkButtonClickEvent(ByVal btnUpdate As LinkButton, ByVal RowIndex As Integer)
        Dim sb As StringBuilder = Nothing

        If btnUpdate Is Nothing Then
            Exit Sub
        End If
        sb = New StringBuilder("return ValidateRow(")
        btnUpdate.Attributes.Add("onclick", sb.ToString)
    End Sub

how do I check for first and last name on the client in insert mode?

Marianne Seggerman

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 27 May 2010, 06:19 PM
found a solution

pulled out all the javascript, wired in required field validators (that is what I needed anyway)

Asked by
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Share this question