Re: Insert break problem

  •  10-13-2004, 11:03 AM

    Re: Insert break problem

    This is my CE Web Custom Control

     
    Code Behind :
     

        Public Class HTMLEditor
            Inherits System.Web.UI.UserControl


    #Region " Web Form Designer Generated Code "

            'This call is required by the Web Form Designer.
            <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

            End Sub

            'NOTE: The following placeholder declaration is required by the Web Form Designer.
            'Do not delete or move it.
            Private designerPlaceholderDeclaration As System.Object
            Protected WithEvents pageEditing As System.Web.UI.WebControls.Literal
            Protected WithEvents lnkSave As System.Web.UI.WebControls.LinkButton
            Protected WithEvents lnkClose As System.Web.UI.WebControls.LinkButton
            Protected WithEvents txtPagePath As System.Web.UI.WebControls.Label
            Protected WithEvents txtPage As System.Web.UI.WebControls.Label
            Protected WithEvents Editor1 As CuteEditor.Editor

            Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
                'CODEGEN: This method call is required by the Web Form Designer
                'Do not modify it using the code editor.
                InitializeComponent()
            End Sub

    #End Region

            Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                If Not Page.IsPostBack Then
                    GetPageHTML()
                End If
                BindEditor()
            End Sub
            WriteOnly Property editpage() As String
                Set(ByVal Value As String)
                    pageEditing.Text = Value
                    txtPagePath.Text = Server.MapPath(Value)
                    txtPage.Text = GetFileContents(txtPagePath.Text)
                End Set
            End Property
            Function GetPageHTML() As String
                Dim InS As Integer = txtPage.Text.IndexOf("<!--EDITABLE-->") + 15
                Dim tmpHTML As String = txtPage.Text.Substring(InS)
                Dim FiS As Integer = tmpHTML.IndexOf("<!--ENDEDITABLE-->")
                tmpHTML = tmpHTML.Substring(0, FiS)
                Editor1.Text = tmpHTML
            End Function
            Function BindEditor()
                Editor1.FilesPath = Global.GetApplicationPath(Request) & "/CuteEditor_Files"
                Editor1.DisableItemList = "New, Delete, Help, Save"
                Editor1.ShowHtmlMode = False
                Editor1.CssClass = Global.GetApplicationPath(Request) & "/style/mserv1.css"
                Editor1.breakMode = CuteEditor.BreakMode.UseParagrapOnCarriage
            End Function
            Function SetPageHTML(ByVal html As String)
                Dim InS As Integer = txtPage.Text.IndexOf("<!--EDITABLE-->") + 15
                Dim Top As String = txtPage.Text.Substring(0, InS)
                Dim Bottom As String = txtPage.Text.Substring(InS)
                Dim FiS As Integer = Bottom.IndexOf("<!--ENDEDITABLE-->")
                Bottom = Bottom.Substring(FiS)
                txtPage.Text = Top & html & Bottom
                SaveTextToFile(txtPage.Text, txtPagePath.Text)
                Page.RegisterStartupScript("ScriptSave", "<script language='javascript'>retLogout = confirm('Changes Saved\n\rDo you wish to close this window?');if(retLogout) parent.CloseWindow(); </script>")
            End Function
            Private Function GetFileContents(ByVal FullPath As String, _
           Optional ByRef ErrInfo As String = "") As String

                Dim strContents As String
                Dim objReader As StreamReader
                Try
                    objReader = New StreamReader(FullPath)
                    strContents = objReader.ReadToEnd()
                    objReader.Close()
                    Return strContents
                Catch Ex As Exception
                    ErrInfo = Ex.Message
                End Try
            End Function

            Private Function SaveTextToFile(ByVal strData As String, _
             ByVal FullPath As String, _
               Optional ByVal ErrInfo As String = "") As Boolean

                Dim Contents As String
                Dim bAns As Boolean = False
                Dim objReader As StreamWriter
                Try
                    objReader = New StreamWriter(FullPath)
                    objReader.Write(strData)
                    objReader.Close()
                    bAns = True
                Catch Ex As Exception
                    ErrInfo = Ex.Message
                End Try
                Return bAns
            End Function

            Private Sub lnkSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkSave.Click
                SetPageHTML(Editor1.XHTML)
            End Sub

            Private Sub lnkClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkClose.Click
                Dim CloseWindow As String = "<script language=""javascript"">parent.CloseWindow()</script>"
                Page.RegisterStartupScript("CloseWindow", CloseWindow)
            End Sub
        End Class

     
    Fore Code :
     
    <table cellSpacing="0" cellPadding="0" width="100%" align="center">
     <tr>
      <td><h5><font color="#aaaaaa">Currently editing page
         <asp:Literal ID="pageEditing" Runat="server"></asp:Literal></font></h5>
      </td>
     </tr>
     <tr>
      <td align="center"><CE:EDITOR id="Editor1" runat="server" EnableFancyDropDownMenu="true"
        ShowLogo="False" ShowBottomBar="True" Width="780px" ></CE:EDITOR></td>
     </tr>
     <tr>
      <td align="center" class="content"><BR>
       <asp:LinkButton id="lnkSave" runat="server">Save Changes</asp:LinkButton>&nbsp;¦&nbsp;
       <asp:LinkButton id="lnkClose" runat="server">Close Window</asp:LinkButton>
       <asp:label id="txtPage" runat="server" Visible="False"></asp:label>
       <asp:label id="txtPagePath" runat="server" Visible="False"></asp:label></td>
     </tr>
    </table>
    What i then do is load the control setting the property  editpage to the absolute path of the page.
    it will open the code inside the tags <!--EDITABLE--><!--ENDEDITABLE--> to edit.
     
    Thats it..
     
    whenever i save it, it shows the A's when it should be paragraphs.
     
    Regards,
     
View Complete Thread