Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Editor / Save in Database

Edit news (choose from the grid below)
If you encounter problems, make sure the ASPNET system process has "write" privileges for the directory. How?
   
  
 
 
   



DeleteEditDateText
No records to display.

  • Database Example

    The main way to save the RadEditor's content in a database is to add your own asp button with database-saving code attached in the button click event handler.The above example does this using an asp datagrid to view the updated content of the database as well as Edit and Delete the content. The Content property is used to get and set the editor content.

    Please, note that the page is not XHTML compliant due to that the <a> tags loaded in RadEditor contain target="_blank" attributes. There isn't a target attribute in XHTML specification.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Theme="Default" Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Editor.SaveInDatabase.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
            <qsf:Header XhtmlCompliant="false" ID="Header1" runat="server" NavigationLanguage="c#" />
            <telerik:RadScriptManager ID="ScriptManager1" runat="server" />

            <script type="text/javascript">
                //<![CDATA[
             function showDiv(div)
             {
             var el = document.getElementById(div);
             el.style.display = (el.style.display == 'none') ? 'block' : 'none';
             }
                //]]>
            </script>

            <qsf:InformationBox ID="InformationBox1" runat="server">
                    Edit news (choose from the grid below)<br />
                    <span style="font-size: 8pt; color: #f60;">If you encounter problems, make sure the
                        ASPNET system process has "write" privileges for the directory. <a href="#" onclick="showDiv('howto1'); return false">
                            How?</a> </span><span id="howto1" style="display: none; margin-left: 30px;">Here's how
                                to set "write" privileges using Windows Explorer (or the IIS management console).<br />
                                1. Right-click on the web applicaton folder, and select Properties.<br />
                                2. Select the "Security" tab.<br />
                                3. Click "Add..." to add a user.<br />
                                4. On the new dialog click "Advanced...".<br />
                                5. On the new dialog click "Find now...".<br />
                                6. Select ASPNET user from the list of available users.<br />
                                7. When you go back to the "Security" tab select the ASPNET user and give it full
                                permissions. </span>
            </qsf:InformationBox>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <table cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td>
                        <input type="hidden" name="EditedNews" runat="server" id="EditedNews" />
                        <telerik:RadEditor ID="NewsEditor" runat="server" Height="300px" SkinID="DefaultSetOfTools">
                            <Modules>
                                <telerik:EditorModule Name="RadEditorStatistics" Visible="false" Enabled="true" />
                                <telerik:EditorModule Name="RadEditorDomInspector" Visible="false" Enabled="true" />
                                <telerik:EditorModule Name="RadEditorNodeInspector" Visible="false" Enabled="true" />
                                <telerik:EditorModule Name="RadEditorHtmlInspector" Visible="false" Enabled="true" />
                            </Modules>
                        </telerik:RadEditor>
                        <br />
                        <asp:Button ID="btnSubmit" runat="server" Text="Submit to Database" OnClick="btnSubmit_Click" />
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <br />
                        <telerik:RadGrid CssClass="borderedGrid" ID="NewsGrid" runat="server" ShowHeader="True"
                            BorderWidth="1" CellPadding="3" AutoGenerateColumns="false" Width="620px" OnItemCommand="NewsGrid_ItemCommand"
                            DataSourceID="SqlDataSource1" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true">
                            <HeaderStyle CssClass="newsTextCentered gridHeader" Font-Names="Verdana" ForeColor="Black"
                                BackColor="#d3e5fa"></HeaderStyle>
                            <MasterTableView EditMode="InPlace" DataKeyNames="NewsID">
                                <Columns>
                                 <telerik:GridBoundColumn DataField="NewsID" UniqueName="NewsID" Visible="false" ReadOnly="true" />
                                 <telerik:GridButtonColumn ButtonType="LinkButton" ItemStyle-CssClass="newsTextCentered" CommandName="Delete"
                                     ItemStyle-Width="50px" HeaderText="Delete" Text="Delete" />
                                 <telerik:GridButtonColumn ButtonType="LinkButton" ItemStyle-CssClass="newsTextCentered" CommandName="Edit"
                                     ItemStyle-Width="50px" HeaderText="Edit" Text="Edit" />
                                 <telerik:GridBoundColumn ItemStyle-CssClass="NewsText" ItemStyle-Width="70px" DataField="NewsDate"
                                     HeaderText="Date" ReadOnly="true" />
                                 <telerik:GridBoundColumn DataField="NewsText" UniqueName="NewsText" ItemStyle-CssClass="text" HeaderText="Text" ReadOnly="true" />
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"

                            DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID"
                            InsertCommand="INSERT INTO [News] ([NewsText], [NewsDate]) VALUES (@NewsText, GETDATE())"
                            SelectCommand="SELECT * FROM [News]"
                            UpdateCommand="UPDATE [News] SET [NewsText] = @NewsText WHERE [NewsID] = @NewsID">
                            <DeleteParameters>
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </DeleteParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
            </table>
            </telerik:RadAjaxPanel>
            <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451