CuteEditor webpage integration

Last post 01-24-2010, 10:04 PM by Sternzy. 5 replies.
Sort Posts: Previous Next
  •  01-10-2010, 1:01 PM 58107

    CuteEditor webpage integration

    Hi, I recently did the how to page in saving xml to a database. After successfully completing it, I migrated the code over to my own page. I'm trying to make the connection pull the xml from CuteEditor and save it to the database. I would like the ID to be an auto incremental number, as opposed to having to enter it manually.
     
    basically I'm trying to take the xml from the CuteEditor and and save it to a sql database, to be displayed on a news page. each post will be a separate news article.
     
    I believe the following in red is where I need to make some changes, I just don't know how to specify CuteEditor as the source.
     
    Thanks for looking.
     
                int ID = Convert.ToInt32(txtID.Text);
                string xmlValue = txtPost.Text; 
     
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
        CodeFile="Post_News.aspx.cs" Inherits="News_Post_News_Default" Title="Post_News" %>

    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Data.Sql" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Data.SqlTypes" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="PortalCPH" runat="Server">

        <script runat="server">

            void btnSave_Click(object sender, EventArgs e)
            {
                int ID = Convert.ToInt32(txtID.Text);
                string xmlValue = txtPost.Text;
                //Get the connection string from the web.config file
                string connString = System.Configuration.ConfigurationManager.ConnectionStrings["SumbmitNews"].ConnectionString;
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
                {
                    conn.Open();
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "Insert News(ID, Post) Values(@ID, @Post)";
                    //Set value of parameters
                    SqlParameter firstColParameter = cmd.Parameters.Add("@ID", SqlDbType.Int);
                    firstColParameter.Value = ID;
                    SqlParameter secondColParameter = cmd.Parameters.Add("@Post", SqlDbType.Xml);
                    secondColParameter.Value = new SqlXml(new XmlTextReader(xmlValue, XmlNodeType.Document, null));
                    //Execute update and close connection
                    cmd.ExecuteNonQuery();
                }
                Response.Write("Saved values successfully");
            }
        </script>

        <div id="Post_News_Head" align="center">
            <h1 style="color: #0000FF">
                Post a News Article.</h1>
            <p style="color: #0000FF; height: 20px;">
                Thank You for Contributing,
                <asp:LoginName ID="LoginName2" runat="server" />
                .</p>
            <hr style="color: #9D9F97; height: 5px;" />
            <div>
                <table align="center" style="width: 100%">
                    <tr>
                        <td>
                            <p align="center">
                                Catagory:
                                <asp:DropDownList ID="DropDownList1" runat="server">
                                </asp:DropDownList>
                                &nbsp; Subcatagory:<asp:DropDownList ID="DropDownList2" runat="server">
                                </asp:DropDownList>
                            </p>
                        </td>
                        <td>
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="cuteeditor" align="center">
            <CE:Editor ID="Editor1" runat="server" Height="226px" />
            <asp:Button ID="btnSave" runat="server" Text="Save Values" Width="118px" Height="30px"
                OnClick="btnSave_Click" />
        </div>
    </asp:Content>

     
  •  01-11-2010, 4:10 AM 58116 in reply to 58107

    Re: CuteEditor webpage integration

    Hi Sternzy ,
     
    Question 1
     
    Text of editor does not have a separate ID, you need to create the id yourself.
     
    Maybe like this
     
     Guid postID = Guid.NewGuid();
     int ID = postID ;
     
    Question 2
     
    If you want to save the data as a new page. Try this way
     
    1. Save the text of editor into database
     
    just need to save as a string(editor1.Text)
     
    2. When you want to load the data from database and save as a page. Using editor to achieve
     
    editor1.Text=GetDataFromDataBase();
    editor1.SaveFile("~/page.htm");
     
    Regards,
     
    Ken
  •  01-18-2010, 2:41 PM 58245 in reply to 58116

    Re: CuteEditor webpage integration

    Thank you for the response.
     
    Rite now I have a data base setup with a table called "News".  In this table I have 10 or so columns that I will eventually tie into each post.
     
    Currentely I am only concerned with the Columns "ID" and "Post". I have the "ID" Column set in SQL Server managment studio to "int" and "primary key".
     
    I would like to simply have a page displaying the CuteEditor. When the "Submit" button is pressed I would like the contents of the CuteEditor to be saved into the tables "Post" Column, with the "ID" column being automatically generated for each post.
     
    Later, i will create a page that retrieves this stored XML to be displayed as news articles.
     
    Here is a couple links so you can see that  I have the General Setup constructed. You may enter whatever you wish to see that it is working. the data being stored in this example is using the same tables and database my own application is using.
     
    Here is a link to the page which I am trying to implement the CuteEditor into.
     
    Below is the code I am currently working with, although I know it needs to be edited. I'm wondering if I even need to include an "ID" declaration, or if this field will be filled in automatically where it is set to "int" and "Primary key".
     
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.Sql;
    using System.Xml;
    using System.Data.SqlTypes;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class News_Post_News_Default : System.Web.UI.Page
    {
        void btnSave_Click(object sender, EventArgs e)
        {
            string xmlValue = Editor1.Text;
            //Get the connection string from the web.config file
            string connString = System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "Insert News(ID, Post) Values(@ID, @Post)";
                //Set value of parameters
                SqlParameter firstColParameter = cmd.Parameters.Add("@ID", SqlDbType.Int);
                firstColParameter.Value = ID;
                SqlParameter secondColParameter = cmd.Parameters.Add("@Post", SqlDbType.Xml);
                secondColParameter.Value = new SqlXml(new XmlTextReader(xmlValue, XmlNodeType.Document, null));
                //Execute update and close connection
                cmd.ExecuteNonQuery();
            }
            Response.Write("Saved values successfully");
        }
    }

     
     
     
  •  01-18-2010, 10:04 PM 58256 in reply to 58245

    Re: CuteEditor webpage integration

    Hi Sternzy ,
     
    In ms sql database, row have a property name identity. when you set it to true, the Columns(in your case name 'ID') will automatic growth.
     
    Regards,
     
    Ken
  •  01-18-2010, 11:45 PM 58257 in reply to 58256

    Re: CuteEditor webpage integration

    Kenneth:
    Hi Sternzy ,
     
    In ms sql database, row have a property name identity. when you set it to true, the Columns(in your case name 'ID') will automatic growth.
     
    Regards,
     
    Ken
     
    Thank you Kenneth for that bit of information, very helpful.
     
    As you can see I am quite new to programming, and am more or less trying to teach myself as I go. I would be grateful if you could point me in the direction of a working example of how a "Post" button can be tied into the actual CuteEditor, as opposed to showing how to save information from a text box.
     
    Thanks again,
    Sternzy
  •  01-24-2010, 10:04 PM 58331 in reply to 58107

    Re: CuteEditor webpage integration

    I just wanted to update this page for anyone else whom might be having problems. I was able to get this working by switching the code back to my .aspx page from the code behind page.
     
    All I did here was paste the code from the XmlDataTypeSave.aspx howto tutorial, then edit a few various pieces that you can inspect below. This is a very simple example, and I will be incorporating many more commands to the asp "Post" button.
     
    Thank you for the help on getting this running!
     
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Post_News.aspx.cs" Inherits="News_Post_News_Post_News" Title="Untitled Page" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Data.Sql" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Data.SqlTypes" %>

        

    <asp:Content ID="Content1" ContentPlaceHolderID="PortalCPH" Runat="Server">
        <script runat="server">

        void btnSave_Click(object sender, EventArgs e)
        {
            string xmlValue = Editor1.Text;
            //Get the connection string from the web.config file
            string connString = System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;        
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();            
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "Insert News(Post) Values(@Post)";
                //Set value of parameters
                SqlParameter firstColParameter = cmd.Parameters.Add("@Post", SqlDbType.Xml);
                firstColParameter.Value = new SqlXml(new XmlTextReader(xmlValue, XmlNodeType.Document, null));
                //Execute update and close connection
                cmd.ExecuteNonQuery();         
            }
            Response.Write("Saved values successfully");
        }
    </script>

    <CE:Editor id="Editor1" runat="server" />

        <asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Post"
            Height="24px" Width="89px" />

    </asp:Content>

View as RSS news feed in XML