Custom Drop Down List : Insert Selected Item in Editor.

Last post 04-27-2011, 8:55 AM by Eric. 3 replies.
Sort Posts: Previous Next
  •  08-10-2009, 3:36 AM 54597

    Custom Drop Down List : Insert Selected Item in Editor.

    Hi,
     
    I want to give a custom dropdown list to user having some predefined values. The user needs to select the item from list and the item should get inserted in the text editor.
     
    I have wrriten code as below:

    CuteEditor.
    ToolControl tc = Editor1.ToolControls["insertcustombutonhere"];

    if (tc != null)

    {

    System.Web.UI.WebControls.DropDownList ddl1 = new System.Web.UI.WebControls.DropDownList();

    ddl1.Items.Add(new ListItem("-- Select Field --"));

    ddl1.Items.Add(new ListItem("$COMPANY_NAME$", "$COMPANY_NAME$"));

    .......
    .......
     
    ddl1.Attributes["Command"] = "PasteText";
    ddl1.Attributes[
    "onchange"] = "CuteEditor_DropDownCommand(this,'" + ddl1.Attributes["Command"] + "')";
     
    ........
    ....
    }
     
     
    I'm facing two problems :
     
    1. Above code is OK on Internet Explorer but not getting results on FireFox.
    2. I'm not able to maintain the recently selected in the Drop down.
     
     
    Please let me know the solution or any idea.
     
    Thanks and regards.
     
    Avinash Vyas
     
     
  •  08-10-2009, 6:06 AM 54602 in reply to 54597

    Re: Custom Drop Down List : Insert Selected Item in Editor.

    HI ashi.avinashvyas,
     
    Try this code
    1. <%@ Page Language="C#" Debug="true" %>   
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5. <html xmlns="http://www.w3.org/1999/xhtml">   
    6. <head runat="server">   
    7.     <title>Untitled Page</title>   
    8.   
    9.     <script runat="server">   
    10.         protected override void OnLoad(EventArgs e)   
    11.         {   
    12.             CuteEditor.ToolControl tc = Editor1.ToolControls["insertcustombutonhere"];   
    13.             if (tc != null)   
    14.             {   
    15.                 System.Web.UI.WebControls.DropDownList ddl1 = new System.Web.UI.WebControls.DropDownList();   
    16.                 ddl1.Items.Add(new ListItem("-- Select Field --"));   
    17.                 ddl1.Items.Add(new ListItem("hello"));   
    18.                 ddl1.Items.Add(new ListItem("show text"));   
    19.                 for (int i = 0; i < ddl1.Items.Count; i++)   
    20.                 {   
    21.                     ddl1.Items[i].Attributes["onclick"] = "showOptionValue(this)";   
    22.                 }   
    23.                 ddl1.Attributes["onclick"] = "simOptionClick()";   
    24.                 tc.Control.Controls.Add(ddl1);   
    25.             }   
    26.             base.OnLoad(e);   
    27.         }   
    28.     </script>   
    29.   
    30. </head>   
    31. <body>   
    32.     <form id="form1" runat="server">   
    33.         <CE:Editor ID="Editor1" runat="server" TemplateItemList="[Bold]/[insertcustombutonhere]/[Italic]">   
    34.         </CE:Editor>   
    35.     </form>   
    36. </body>   
    37. </html>   
    38.   
    39. <script type="text/javascript">        
    40.  function simOptionClick()   
    41.  {         
    42.   
    43.     var evt=window.event  ;         
    44.     var selectObj=evt?evt.srcElement:null;         
    45.     if (evt && selectObj &&  evt.offsetY && evt.button!=2         
    46.         && (evt.offsetY > selectObj.offsetHeight || evt.offsetY<0 ) )    
    47.         {         
    48.             setTimeout(function(){         
    49.                 var option=selectObj.options[selectObj.selectedIndex];         
    50.                               showOptionValue(option)         
    51.                  }, 60);         
    52.         }         
    53. }         
    54.   
    55. function showOptionValue(opt)   
    56. {      
    57.   var editor1 = document.getElementById('<% = Editor1.ClientID%>');   
    58.   editor1.PasteHTML(opt.text);        
    59.      
    60. }         
    61. </script>  
    Regards,
     
    Ken
  •  04-27-2011, 8:20 AM 67346 in reply to 54602

    Re: Custom Drop Down List : Insert Selected Item in Editor.

    I'm facing the same problem.
     
    What's the proper way to achieve adding a custom ddl to the toolbar?
  •  04-27-2011, 8:55 AM 67347 in reply to 67346

    Re: Custom Drop Down List : Insert Selected Item in Editor.

    Dear Sergejack,
     
    Please refer to "\Framework 2.0\HowTo\RichDropDown\cs\customize_dropdown.aspx", you can find its source code in download package.
     
    Thank you for asking
View as RSS news feed in XML