Saving To DataBase

3 posts, 0 answers
  1. Harry
    Harry avatar
    11 posts
    Member since:
    Feb 2011

    Posted 19 Feb 2011 Link to this post

    Hi all
    I have spent Alot time working with the edit radcotrol and I have followed the example in the documentation and I am have a hard time getting the radedit1.content to save
     there is the code

     

     

     

    string sqlserver = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

     

     

     

    string user_id;

     

     

     

    protected void Page_Load(object sender, EventArgs e)

     

     

    {

     

     

    string userID = Context.User.Identity.Name;

     

     

    lookupid(userID);

     

    getbody(user_id);

     

    }

     

     

    public void getbody(string userID)

     

     

    {

     

     

    SqlConnection conmydata = new SqlConnection(sqlserver);

     

     

    conmydata.Open();

     

     

    SqlCommand cmdselect = new SqlCommand("select txtarea from txtbody where @userID=userID", conmydata);

     

     

    cmdselect.Parameters.AddWithValue(

    "@userID", userID);

     

     

     

    string strbody = Convert.ToString(cmdselect.ExecuteScalar());

     

     

    conmydata.Close();

     

    RadEditor1.Content = strbody;

     

    }

     

     

    public void lookupid(string userID)

     

     

    {

     

     

    SqlConnection conmydata = new SqlConnection(sqlserver);

     

     

    conmydata.Open();

     

     

    SqlCommand cmdselect2 = new SqlCommand("select userID from users where @userID=email_address", conmydata);

     

     

    cmdselect2.Parameters.AddWithValue(

    "@userID", userID);

     

     

     

    string stremail = Convert.ToString(cmdselect2.ExecuteScalar());

     

     

    conmydata.Close();

     

    user_id = stremail;

     

    }

     

     

    public void edit_finish(object sender, EventArgs e)

     

     

    {

     

     

    string body = RadEditor1.Content;

     

     

     

    SqlConnection conmydata = new SqlConnection(sqlserver);

     

     

    conmydata.Open();

     

     

    SqlCommand insert = new SqlCommand("update txtbody set txtarea=@txtarea where userID=@userID", conmydata);

     

     

    insert.Parameters.AddWithValue(

    "@txtarea", body);

     

     

    insert.Parameters.AddWithValue(

    "userID", user_id);

     

     

    insert.ExecuteNonQuery();

     

    conmydata.Close();

     

    }

     

     

     

  2. Harry
    Harry avatar
    11 posts
    Member since:
    Feb 2011

    Posted 19 Feb 2011 Link to this post

    I have been working with this problem and found out when the text is updated in the editor the radedit1.content is not changed has anyone seen this problem before?
  3. Rumen
    Admin
    Rumen avatar
    13849 posts

    Posted 22 Feb 2011 Link to this post

    Hi Harry,

    The problem is more likely related to overriding the editor content yourself, in your Page_Load method. Please note that if you read the content of the editor in an event handler (such as a button event handler) this event handler executes later in the page lifecycle compared to Page_Load. This is why, in case you set the initial content in Page_Load it is mandatory to add a check, e.g.

    if (!Page.IsPostBack)
    {
        RadEditor1.Content = "Some content";
    }

    You can check the code of the following demos which could be helpful for your scenario:
    Save In Database
    and
    Datagrid Edit Template.

    In case you are having any difficulty, our suggestion is to implement your scenario using a simple <asp:TextBox> instead of RadEditor. Once you get the textbox to work as needed, all you need to do is change the textbox to RadEditor - and all should be fine.

    In case you are able to implement your scenario with a simple <asp:TextBox>, yet you are facing trouble with the RadEditor, please send us your working project in a support ticket and we will make the change for you.

    Best regards,
    Rumen
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top