How to access page control (editor control) from user control?

Hi,

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
 

0
cornelis79
2/15/2007 11:50:27 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
1708 Views

Similar Articles

[PageSpeed] 46
Get it on Google Play
Get it on Apple App Store

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
  Inherits EventArgs

  Public ReadOnly Content As String

  Friend Sub New( cont as String )
    Content = cont
  End Sub
End Class

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.


Regards

Dave
0
DMW
2/15/2007 12:24:11 PM

DMW,

 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
 

0
cornelis79
2/15/2007 2:33:11 PM
Reply:

Similar Artilces:

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

Accessing controls on user control page
I have a main page that interfaces with a web service and returns a dataset.  I also have a user control page that contains a datagrid.  I have the user control registered and displaying on the main page.  However, I don't know how to gain access to the datagrid on the user control from the code on the main page.  There doesn't seem to be a way to directly assign values to the properties of the datagrid like you could if it were on the main page itself.  I can't seem to just do:GridView1.DataSource = Contact; GridView1.DataBind();  because I can...

How to access one user control from another user control on same page
hi,I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this?I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only.plz helpregards,max   Hi Max, you have to expose your DropDownList as a public property which lays inside usercontrol 1. Example: 1 class MyUserControl1 : UserControl 2 { 3 4 p...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

access controls in user control on a master page
Have a simple question.. I have a dropdown list in a user control within a master page.When I change selection in ddl, I want to access value on the content page.For that, right now I need to refresh the page.. don't know why.. one way around this cud be to declare a public property for UserControl and access it, but I can ONLY see this UserControl in MasterPage... not in a content pageWhile rendering, first content page loads, then MasterPage.. so I can not access changed/current value in the dropdown.. Can someone help?-------------------------------------------------Click on &...

How do I access a control in a page from within a user control?
Hi all, I'm trying to access a hidden field in a page from within a user control but whatever I try just doesn't work. So how can I access controls in a page from within a user control? Thanks use this in ur user control HiddenField HF= (HiddenField)this.Page.FindControl(""HdnControlID");Mark the post as answer if it helps you!Ashish Agrawal----------------------------MCPD(.NET Framework 2.0,Web Developer)MCTS(SQL Server 2005) Make sure the hidden field runs at server (runat="server")Jef Claes~~~~~~~~~~Visit my blog HiddenField HF= (HiddenField)this....

Access controls in User Control in Page Load
What is the better way of getting values from a user control in the load event of the page containing the user control. In my scenario the user control has some drop downs and based on the selections it gather info from the db through ajax. Now I want to access these values and selected values on load event of the container. One way to do this is to make public 0width textboxes in user control and then access them in postback. But that is i guess the pathetic way as different browsers will render 0width textboxes in their own style also i have to make them public which i am not comfortable w...

How to access a master page control in a user control.
Hi All, I need to access a scriptmanager control placed in a Master page. The scriptmanager is used to RegisterClientScript in the Custom User Control.  The UserControl is placed in a child web page of the Master page. How do I do this? Thanks in advance, Rohan.      There's a ScriptManagerProxy control you can use for this; just drop it onto the user control and you can use that instead....

Access controls on host page from a user control
Is it possible to access web server controls on a aspx page from a user control which is hosted by this aspx page. cheers Hi, Suppose you have a textbox in your page named txtFirstName and you want to get that value when the user clicks a button on the User Control. On the click event of the User Control Button write the following linesControl txtFirstNameControl = this.Page.FindControl("txtFirstName"); lblStatus.Text = ((TextBox)txtFirstNameControl).Text; Happy programming,Anton Thanks Anton. It worked. Cheers    ...

Accessing control on user control from aspx page
Is it possible to access, say an image to make not visible on a user control, .ascx, from an aspx page containing that control? That is, in the code behind from the .aspx page, making an image.visible=false on the .ascx page. Thanks all, Zath your user control should expose a public property such as: ImageVisible from the container (the page), you'd set that usercontrols property to true or false. from the usercontrol (perhaps in the prerender event), youd set the visibility of the image based on the value of the ImageVisible property. you should not directly manipulate ...

How to access control of a User Control from an aspx page
I have got one aspx page and one user control. I am using the user control in an aspx page. User Control has four textbox, and I want to get the text(or value) of those textbox from the aspx page where I am using the user control. I looked the Duwamish project, and try to emulate the exact way they are using, by make the class public. But, i can't do that. "Object reference not set to an instance of an object" is the error that I am getting. I tried the whole day to solve this problem. But could not. Please help me. Here is something you might try:1. Keep a reference of the user co...

Get page controls property in User control
I have a aspx page and there is a button. I want to access this button properties in my User control. How can I do so.Yes the user control is on my aspx page You can find the button with the FindControl method. Button btnFoo = (Button)Page.FindControl("buttonId"); string id = btnFoo.id;Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.  this does not work. It returns me null.To be clear button is on my web page aspx and want to access its properties on the user control ascx Is you button nested in other controls? (eg...

access parent page controls in a user control
 hi guys   i am using two user controls with in a user control and this main user is added to a page.How can i access the main user control's methods, controls from the child user control and vice versa?also i want to access the controls,methods of main user control from page and vice versa.. Hari Krishnantechiebuddy.com Hi,In order to use methods of child controls make the methods you need public and call them in the parent user control.In order to use controls within child controls make public properties that expose the relevant operations for the inner controls of you...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Web resources about - How to access page control (editor control) from user control? - asp.net.getting-started

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Out-of-control car hits Ballajura pedestrians and puts four teens in hospital
Four teenagers were injured in Ballajura on Saturday night when an out-of-control car careered into them.

Is Hillary Clinton sorry she reacted to the San Bernardino massacre with a call for more gun control ...
... "Gun safety" has traditionally meant handling your guns safely, but now it's supposed to mean what has more commonly been called "gun control." ...

Obama renews call for gun control after mass shooting
In wake of San Bernardino attack, president, Republicans float their solutions to combat terror threats

EU could soon have border controls
EU ministers have agreed to press ahead with plans to suspend the Schengen passport-free travel zone, the FT reports.

CNN's Smerconish Brings On GOP Ratf*er Karl Rove To Opine Over Partisan Divide On Gun Control
... was time to pray. The New York Daily News ran a controversial cover noting that God wouldn't fix this. Democrats again made calls for gun control. ...

Attorney General Says Obama Could Call For Congressional Action For More Gun Control
Attorney General Says Obama Could Call For Congressional Action For More Gun Control

Open thread for night owls: First U.S. birth control clinic lasted just 10 days before being raided
... Parenthood Only Lasted for 10 Days but Started a Revolution . An excerpt: During her time in Europe, Sanger had seen Norwegian birth control ...

San Bernardino Shooting: National Rifle Association rubbishes Obama's gun-control appeal
San Bernardino Shooting: National Rifle Association rubbishes Obama's gun-control appeal - Hitting out at Barack Obama for politicising the incident, ...

Facebook Gives Users More Control Over Viral Content In News Feed
Facebook is updating its algorithm to give users more control over how high viral content appears in their News Feed.

Resources last updated: 12/6/2015 10:51:59 PM