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

Client-side function setting Editor content fails in Master Page

2 Answers 71 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Jesse Lawler
Top achievements
Rank 1
Jesse Lawler asked on 25 Apr 2010, 07:19 PM
I'm unable to access my RadEditor using client-side Javascript functions when I use a Master Page.  The identical code works fine when it's not set in a Master Page.  (This is a super-simple example, lifted straight from Telerik's demos.)

The code for the page is here:

<%@ Page Title="" Language="C#" MasterPageFile="~/AltMasterPage.master" AutoEventWireup="true" CodeFile="Test2.aspx.cs" Inherits="Documentation_Test2" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="SecondLevelHeadContent" Runat="Server">
    <script type="text/javascript">
        function SetHtml() {
            var newValue = $get('textHtml').value;
            $find("RadEditor1").set_html(newValue);
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="SecondLevelBodyContent" Runat="Server">
     <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
     <telerik:RadEditor ID="RadEditor1" runat="server" />
     <div class="module">
     <input type="button" value="Set New Html to the RadEditor" onclick="SetHtml()"/>
     <input type="text" value="New HTML" id="textHtml" />
     </div>     
</asp:Content>

And for the Master Page is here:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="AltMasterPage.master.cs" Inherits="MasterPage" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <asp:ContentPlaceHolder id="SecondLevelHeadContent" runat="server" />
</head>
<body>
    <form id="form1" runat="server">               
        <asp:ContentPlaceHolder id="SecondLevelBodyContent" runat="server" />
    </form>
</body>
</html>

The Javascript error thrown is: 
$find("RadEditor1") is null  

The exact same code works like a champ if it's in an ASPX file that doesn't reference a Master Page.  What's going on?

Thanks,

Jesse

2 Answers, 1 is accepted

Sort by
0
Vincent
Top achievements
Rank 1
answered on 25 Apr 2010, 10:40 PM
Hi Jesse

Because of the naming container, you have to use ClientID to get the real id of that control. In your case, you have to use 
  $find("<%=RadEditor1.ClientID%>").set_html(newValue);
0
Jesse Lawler
Top achievements
Rank 1
answered on 26 Apr 2010, 12:48 AM
Thank you!
Tags
Editor
Asked by
Jesse Lawler
Top achievements
Rank 1
Answers by
Vincent
Top achievements
Rank 1
Jesse Lawler
Top achievements
Rank 1
Share this question
or