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

Client Events Break $find

2 Answers 63 Views
This is a migrated thread and some comments may be shown as answers.
Marcus Kellermann
Top achievements
Rank 1
Marcus Kellermann asked on 20 Oct 2010, 08:54 PM
I have a simple page that when I add a OnRowSelected client site event handler, it breaks the $find command for finding the RadGrid  

If I remove the ClientSettings section and just use a button to execute the same javascript it works fine.  I don't understand why adding the client settings is breaking $find.  When the client settings are there $find always returns null. 

Master Page File
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="radWindowExample.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">
<head runat="server">
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    <form runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                    My ASP.NET Application
            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                        [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        <div class="clear">
    <div class="footer">

Webform Markup
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="radWindowExample.WebForm4" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script language="javascript">
        var messageId;
        var grid;
        function PreventRowSelection(index) {
            if ((this.Rows[index].ItemType == "Item" || this.Rows[index].ItemType == "AlternatingItem")) {
                return false;

        //------dgMessages.ClientID is returning NULL ----THIS IS THE ERROR-----------//
        function CheckSelections() {
            //added the line below
            alert($find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems().length);
            //var MasterTable = grid_1.get_masterTableView();
            //var srows = MasterTable.get_selectedItems();
            messageId = "";
            if (srows.length == 1) {
                messageId = srows[0].KeyValues["ID"];
                DisableButtons(false, false);
            else if (srows.length > 1) {
                DisableButtons(true, false);
            else {
                DisableButtons(true, true);
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"
    CellPadding="0"  EnableAJAX="True"
    EnableAJAXLoadingTemplate="True" GridLines="None" PageSize="25"
    <CommandItemStyle />
        <Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in"
        PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" />
    <PagerStyle BackColor="#6699CC" HorizontalAlign="Justify" />
    <ClientSettings >
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" />
        <Scrolling AllowScroll="False" />
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="False"></Selecting>
        <ClientEvents OnRowSelected="CheckSelections()" />
    <HeaderStyle BorderColor="#6699CC" BorderStyle="Solid" BorderWidth="0px" HorizontalAlign="Left" />
     <PagerStyle NextPageText="Next &gt;" PrevPageText="&lt; Prev" />
<input type="button" onclick="CheckSelections(); return false;" value="Hello" />

Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace radWindowExample
    public partial class WebForm4 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            DataTable dtRagGrid = new DataTable();
             dtRagGrid.Rows.Add("john", "1");
            dtRagGrid.Rows.Add("Mark", "2");
             RadGrid1.DataSource = dtRagGrid;

2 Answers, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 21 Oct 2010, 10:11 AM
Hello Marcus,

The problem comes from the way you have attached the handler - when you add the brackets (), you actually call and execute the function once. In order to attach a handler you should not call the function, but you should only provide the function's name.

That is, when declaring client-side event handlers, you need to use function names instead of execution of the function.

<ClientEvents OnRowSelected="CheckSelections" />

Hope this helps,
Marcus Kellermann
Top achievements
Rank 1
answered on 21 Oct 2010, 01:21 PM
That was part of the problem but even after that change it still failed.  I had to change the logic for getting the masterTableView to the following.

function CheckSelections()
    var radGrid = $find("<%=RadGrid1.ClientID%>");
    var masterTable = radGrid.get_masterTableView();
    var length = masterTable.get_selectedItems().length;

But what I don't understand is why it didn't work before and why an error in one javascript function was breaking all the scripts in the page.
Asked by
Marcus Kellermann
Top achievements
Rank 1
Answers by
Top achievements
Rank 2
Marcus Kellermann
Top achievements
Rank 1
Share this question