Re: Losing Editor content when saving

  •  08-15-2008, 8:53 AM

    Re: Losing Editor content when saving

    Adam,
     
    Here is the ascx:
     

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PM_Add.ascx.cs" Inherits="xxx.yyy" %>

    <asp:UpdatePanel ID="up_PMAdd" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
      <table width="100%">
       <tr>
        <td colspan="3">
         To:
         <asp:DropDownList ID="ddl_SentTo" runat="server" />
        </td>
       </tr>
       <tr>
        <td colspan="3">
         Subject:
         <asp:TextBox ID="TextBox1" runat="server" Width="300px" TabIndex="1" />
        </td>
       </tr>
       <tr>
        <td colspan="3">
         
         <VHA:Editor ID="Editor_NewPM_Counselor" runat="server" AllowPasteHtml="false" Width="100%"
          Height="250px" ConfigurationPath="~/CuteSoft_Client/CuteEditor/Configuration/AutoConfigure/VHAMinimal.config"
          ConvertHTMLTagstoLowercase="true" EditorOnPaste="Default" ShowBottomBar="false" />
        </td>
       </tr>
      </table>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Literal ID="lbl_AutoSave" runat="server" />
    <asp:Timer ID="Timer_PMAdd" runat="server" Interval="15000" OnTick="Timer_PMAdd_Tick" />
    <span style="visibility: hidden;">
        <asp:Button ID="Button1" runat="server" /></span>
    <VHAAjax:ModalPopupExtender ID="mpu_AutoSave" BehaviorID="mdlPopup" runat="server"
        TargetControlID="Button1" PopupControlID="pnl_AutoSave" BackgroundCssClass="modalBackground" />
    <asp:Panel ID="pnl_AutoSave" runat="server" CssClass="confirm-dialog" Style="display: none;">
        <div class="inner">
            <h5>
                You are reaching the end of your session.</h5>
            <p style="padding-right: 20px; text-align: justify;">
                In order for you to keep the data you have entered so far, it will be saved for
                you. The page will reload and you can continue typing your message.</p>
            <asp:Button ID="btn_AutoSave" runat="server" Text="Save" OnClick="btn_AutoSave_Click" />
            <p>
            </p>
        </div>
    </asp:Panel>

    And here is the codebehind
     

    using System;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Profile;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using VHA.OCC.BLL;

    namespace xxx
    {
        public partial class yyy : System.Web.UI.UserControl
        {
            string cs_Live = ConfigurationManager.ConnectionStrings["XXX"].ConnectionString;
            string AutoSave = "";

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {  
                    if (Request.QueryString["AutoSave"] != null)
                    {
                        AutoSave = Request.QueryString["AutoSave"].ToString();
                    }
                   
                    if (AutoSave == "")
                    {
                        //Do all initial display of controls
                    }
                    else
                    {
                        //Grab the data and put it in the controls ie.  Editor_PM_Add.Text = reader["xxx"];
                    }
                }
            }

            protected void Timer_PMAdd_Tick(object sender, EventArgs args)
            {
                Timer_PMAdd.Enabled = false;
                mpu_AutoSave.Show();
            }

            protected void btn_AutoSave_Click(object sender, EventArgs e)
            {
                string SID = Session.SessionID.ToString() + Session["NewLoginID"];
                string tempSubject = "";
                string tempMessage = "";
                string tempSendTo = "";

       tempSendTo = ddl_SentTo.SelectedValue.ToString();
       tempSubject = TextBox1.Text.Replace("'", "''");
       tempMessage = Editor_NewPM_Counselor.Text.Replace("'", "''");

       string aSql = "SELECT SessionID FROM XXX WHERE SessionID LIKE '" + SID + "'";

                SqlConnection aConn = new SqlConnection(cs_Live);
                aConn.Open();
                SqlCommand aComm = new SqlCommand(aSql, aConn);
                SqlDataReader a;
                a = aComm.ExecuteReader();

                if (a.Read())
                {
                    string bSql = "UPDATE XXX SET MessageContent = '" + tempMessage + "', MessageSubject = '" + tempSubject + "' WHERE SessionID LIKE '" + SID + "'";
                    SqlConnection bConn = new SqlConnection(cs_Live);
                    bConn.Open();
                    SqlCommand bComm = new SqlCommand(bSql, bConn);
                    bComm.ExecuteNonQuery();
                    bConn.Close();

                    Response.Redirect("PM_Add.aspx?AutoSave=" + DateTime.Now.ToUniversalTime() + "", true);
                }
                else
                {
                    string cSql = "INSERT INTO XXX (SessionID, MessageType, MessageContent, MessageSubject) VALUES ('" + SID + "', 'PM', '" + tempMessage + "', '" + tempSubject + "')";
                    SqlConnection cConn = new SqlConnection(cs_Live);
                    cConn.Open();
                    SqlCommand cComm = new SqlCommand(cSql, cConn);
                    cComm.ExecuteNonQuery();
                    cConn.Close();
                }
                a.Close();
                aConn.Close();

                Response.Redirect("PM_Add.aspx?AutoSave=" + DateTime.Now.ToUniversalTime() + "", true);
            }

        }
    }
     
    By the way, I'm running the latest version 6.1.2
View Complete Thread