populating the editor via listbox c#/javascript, how to refernce the textareas ID

Last post 01-14-2011, 4:16 AM by javariajee. 4 replies.
Sort Posts: Previous Next
  •  01-13-2011, 5:43 AM 65704

    populating the editor via listbox c#/javascript, how to refernce the textareas ID

    hi all,
     
    what im trying to do is populate the editor with a value from a listbox on double click, ive added the attributes but i cant figure out how to reference the editors ID to populate it
     
    this is on the page_load event, obviously the editor1.text ="test"; works, but i cant get the editor to be populated
    the listitem var works fine on the alert its just the putting it in the editor im having trouble with 
     
    can anyone help me out?
    Thanks 
    1. Editor1.Text = "test";  
    2.   
    3. var ListItem = "document.forms[0]['" + FieldsList.ClientID + "'].value";  
    4. //FieldsList.Attributes.Add("ondblclick", "BLOCKED SCRIPTalert(" + ListItem + ");");  
    5. FieldsList.Attributes.Add("ondblclick""document.forms[0]['Editor1'].Value +=" + ListItem);  
     
  •  01-13-2011, 2:44 PM 65711 in reply to 65704

    Re: populating the editor via listbox c#/javascript, how to refernce the textareas ID

    Dear AWilderbeast,
     
    Please refer to the following code:
     
    Default5.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <!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 runat="server">
        <title></title>
        <script type="text/javascript">
            function setContent() {          
                // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');    
        editor1.setHTML("this is a test");
             }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
       <table>
       <tr>
       <td>
        <asp:ListBox ID="FieldsList"  runat="server" rows="20" width="200px" 
                >        
                        </asp:ListBox>
       </td>
       <td>
         <CE:Editor id="Editor1"  ThemeType="Office2007" EditCompleteDocument="true" AllowPasteHtml="false" runat="server" ></CE:Editor><BR>
     
       </td>
       </tr>
      
       </table>
        </div>
        </form>
    </body>
    </html>
     
    Default5.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class Default5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Dictionary<string, string> list = new Dictionary<string, string>();
         
            list.Add("1", "Please Select a Category1");
            list.Add("2", "Please Select a Category2");
            list.Add("3", "Please Select a Category3");
            list.Add("4", "Please Select a Category4");
            FieldsList.DataSource = list;
            FieldsList.DataTextField = "Value";
            FieldsList.DataValueField = "Key";
            FieldsList.DataBind();
            // FieldsList.Attributes.Add("ondblclick", "document.forms[0]['" + TextBox1.ClientID + "'].value += " + ListItem);
            //FieldsList.Attributes.Add("ondblclick", 'BLOCKED SCRIPTreturn confirm(‘Are you sure to save?’);');
             FieldsList.Attributes.Add("ondblclick","j avascript:setContent();");       }
       }


    Thank you for asking
  •  01-14-2011, 2:51 AM 65718 in reply to 65711

    Re: populating the editor via listbox c#/javascript, how to refernce the textareas ID

    thanks!
     
    that works, but how can i make it append the text instead of set?
     
    at the moment, when you press the button it sets the text of the entire field, so if i type
     
    "hello my name is alex" then press the button it changes to" this is a test" when i want it to say
     
    "hello my name is alex this is a test" 
     
    ive tried
    editor1 += editor1.setHTML("this is a test");  but no luck
     
    thanks eric 
  •  01-14-2011, 2:54 AM 65719 in reply to 65718

    Re: populating the editor via listbox c#/javascript, how to refernce the textareas ID

    i figured it out
     
    editor1.setHTML(editor1.getHTML() + "this is a test"); 
  •  01-14-2011, 4:16 AM 65720 in reply to 65704

    Re: populating the editor via listbox c#/javascript, how to refernce the textareas ID

    Thanks! This is something I've really missed and was very happy to find. :)

    acne and treatment
View as RSS news feed in XML