The Code snippets dropdown is a very convenient tool for inserting predefined chunks of content (HTML) like signatures, product description templates, custom tables, etc. The snippets are kept in the Snippets collection. You can programmatically populate the Code snippets dropdown menu by using the Add method for this Collection.
In the following example, we will construct a new set of Code snippets with two items - a Product Template and an e-mail Signature:

To define those two Code snippets with the Add method use the code below:
| ASPX |
Copy Code |
|
<rad:RadEditor id="RadEditor1" Runat="server"></rad:RadEditor> |
| C# |
Copy Code |
|
|
| VB.NET |
Copy Code |
|
RadEditor1.Snippets.Add("Product Template", "<table> <tr> <td><img src='http://www.telerik.com/DEMOS/ASPNET/Editor/Img/productLogo.gif' /> </td></tr></table>") RadEditor1.Snippets.Add("Signature", "<strong>John Smith</strong><br>Sales Manager<br>") |
To create a dropdown with image thumbnails you have to insert the img tag as the first argument of the Add method. The img tag content is the path to the image source, e.g:
| C# |
Copy Code |
|
RadEditor1.Snippets.Add("<img src='./RadControls/Editor/Skins/Default/Buttons/Cut.gif' /> test", "test"); |
| VB.NET |
Copy Code |
|
RadEditor1.Snippets.Add("<img src='./RadControls/Editor/Skins/Default/Buttons/Cut.gif' /> test", "test") |
You can also populate the Custom links dropdown using the ToolsFile.xml file. In order for the HTML code to be interpreted correctly in the XML file, you need to enclose it in <![CDATA[ ]]> as shown in the example below:
To set an image icon in an "Insert Code Snippet" item, just put an IMG tag either in front of or next to the Title inside the name attribute of the respective snippet tag:
<snippet name="<img src='http://www.telerik.com/RadControls/Editor/Skins/Custom/buttons/AjaxSpellCheck.gif' />Order Confirmation">
You should also encode the < and > tags symbols of the IMG tag with < and >.
 |
Please, bear in mind that the Telerik RadEditor will persist its state (including the Code Snippets set) between postbacks. In order to create a new set of Code Snippets (e.g. for different users), you will need to clear it first. This can be done using Remove method from Snippets collection.
|
See Also