I want to do something, but I don't know if it's even possible.
I'm trying to make a simple application to edit my website.
I have a page called editPage.aspx which contains an editor control. (cuteEditor from cutesoft)
I also have a Treeview that dynamically populates my website structure. I placed this treeview in a custom control (populateTreeView.ascx) and placed it on the editPage.aspx page.
When you click on a html file in the treeview (inside the custom control) I check if the file exists. If it does exists I send it to a class which retrieves the editable region within this html file.
I made regions like <!-- edit start --> and <!-- edit end -->
I pick out the text between these regions.
I want to pass this text to the editor, but I don't know how.
This is because the text is returned to my custom control page. (populateTreeView.ascx.vb)
How can I send the retrieved text to my editor control? My custom control page doesn't see the editor control.
The custom control is more like a frame within my editPage.aspx page.
Any ideas how to pass the object?
Of course I can place the treeview and its code directly on the editPage.aspx page, but I would rather be able to reuse the custom control for other parts of the website and do the same trick.
Here is my some of my code to illustrate:
editPage.aspx:<form id="form1" runat="server"> <table> <tr> <td valign="top" width="250"> <uc1:populateTreeview ID="PopulateTreeview1" runat="server" /> <!-- my user control --> </td> <td valign="top"> <div align="center"> <CE:Editor ID="Editor1" runat="server" AutoConfigure="Full_noform" Height="500px" AllowPasteHtml="false" EditCompleteDocument="false" FilesPath="~/editor/Cutesoft_client/CuteEditor"> <FrameStyle BackColor="White" BorderColor="#DDDDDD" BorderStyle="Solid" BorderWidth="1px" CssClass="CuteEditorFrame" Height="100%" Width="100%" /> </CE:Editor> <br /><br /> </div> </td> </tr> </table> </form>
populateTreeview.ascx.vb:1 Protected Sub MyTree_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTree.SelectedNodeChanged 2 Dim editPage As FileInfo = New FileInfo(Server.MapPath(MyTree.SelectedValue)) 3 If editPage.Exists Then 4 Dim retrieveContent As loadHtml = New loadHtml(editPage.FullName) 5 Dim editableContent As String = retrieveContent.getHtml() 6 'now I have to pass the editContent to my editor somehow.... 7 End If 8 End Sub
This is the way that I'd do it.
Have you custom treeview control raise a custom event (where you've got the 'now I have to pass ... comment in the code)
Define the eventargs class for this event as
Public Class ContentChangedEventArgs
Public ReadOnly Content As String
Friend Sub New( cont as String )
Content = cont
Define the event as
Public Event ContentChanged As EventHandler(Of ContentChangedEventArgs )
Handle this event in your page, read the content from the ContentChangedEventArgs Content property and then set the content in the cute editor.
Now you can reuse the control on as many pages as you want.
Thanks for your suggestion to help me on my way.
At first I had no idea what you where talking about (I'm still a novice) because I don't have much experience with custom events.
But your idea looked promising so I decided to "look into" the subject.
Finally, thanks with this site: ONDotnet.com, I was able to solve my problem by create a custom event for my custom control.
Here is my code that solved it:
Within my populateTreeView.ascx.vb page:Partial Class populateTreeview Inherits System.Web.UI.UserControl 'Class within my Partial Class Public Class EditContentArgs Inherits EventArgs Public editableContent As String End Class Protected WithEvents treeView As System.Web.UI.WebControls.TreeView Public Event editContentRetrieved(ByVal sender As Object, ByVal e As EditContentArgs) 'Some other code to populate treeview ... Protected Sub MyTree_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTree.SelectedNodeChanged Dim editPage As FileInfo = New FileInfo(Server.MapPath(MyTree.SelectedValue)) If editPage.Exists Then Dim retrieveContent As loadHtml = New loadHtml(editPage.FullName) Dim editableContent As String = retrieveContent.getHtml() 'now I have to pass the editContent to my editor somehow.... 'Solved by passed my variable through a custom event Dim eca As EditContentArgs = New EditContentArgs() eca.editableContent = editableContent RaiseEvent editContentRetrieved(sender, eca) End If End Sub End Class
On my editPage.aspx.vb page:
Protected Sub PopulateTreeview1_editContentRetrieved(ByVal sender As Object, ByVal e As populateTreeview.EditContentArgs) Handles PopulateTreeview1.editContentRetrieved Editor1.Text = e.editableContent End Sub