External JS file cannot detect telerik items

2 posts, 0 answers
  1. Hossam
    Hossam avatar
    5 posts
    Member since:
    Jan 2014

    Posted 24 Jan 2014 Link to this post

    I try to work with telerik button using client side in external JS file but i cannot detect it, but when i put the code inside the page it works good.
    this is Page HTML code 
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html>
    <head runat="server">
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript" src="JavaScript.js"></script>
        <form id="form1" runat="server">
            <telerik:RadButton ID="RadButton1" runat="server" Text="RadButton" OnClientClicked="test"></telerik:RadButton>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
    and this is my JS file code
    function test(sender,args) {
        var button = $find("<%= RadButton1.ClientID %>");
    thanx in advance
  2. Marin Bratanov
    Marin Bratanov avatar
    3562 posts

    Posted 27 Jan 2014 Link to this post

    Hi Hossam,

    Server code blocks (<%= ..... %>) can only be used in compiled files (aspx, ascx) and not in external files that are not parsed by the ASP engine. Perhaps this blog post can show you one way of working with control references: http://blogs.telerik.com/jefffritz/posts/13-01-21/simplify-javascript-control-references-in-asp.net-webforms.

    On a side note - the client-side events our controls raise pass the control instance as a first argument, so you can use that instead:
    function test(sender,args) {

    Marin Bratanov
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. DevCraft R3 2016 release webinar banner
Back to Top