This is a migrated thread and some comments may be shown as answers.

RadEditor Exception: Multiple controls with the same ID '__Page' were found.

7 Answers 150 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Zash
Top achievements
Rank 1
Zash asked on 21 Oct 2009, 01:35 PM

PLEASE HELP!!!

We are using RAD Editor for .Net 2.0 v6.6.3.0

We are trying to add two RadEditors from code behind to  a page by using a wrapper class. Sample code:

using Telerik.WebControls;  
 
public class TextEditorControl : System.Web.UI.Page  
{  
    protected RadEditor editor;  
    protected string id;  
      
    public TextEditorControl(string id) : base()  
    {  
        editor = new RadEditor();  
        this.id = id;  
    }  
 
    protected override void OnInit(EventArgs e)  
    {  
        // Initialize all necessary properties  
        editor.Editable = true;  
        // ...  
 
        this.Controls.Add(editor);  
        editor.ID = this.id;    // Changing editor id from "ctl00" to our custom id
    }

Later we add this control to one of the tabs in our main display page. Sample code:

public class MainPage : System.Web.UI.Page  
{  
    protected override void OnInit(EventArgs e)  
    {  
        //Add controls to the page based on an xml settings file  
        //...  
        TableCell tdContainer;  
          
        if (controlType = "TextEditorControl")  
        {  
            tdContainer.Controls.Add(new TextEditorControl(controlId));  
        }  
 
        //Other code  
        //...  
    }  
 
    protected void Page_Error(Object sender, EventArgs e)  
    {  
        //Catch the error as an exception  
    }  

For the first time, both RadEditor controls load fine. Then if we navigate to the next tab in the page, and try to navigate back to the previous tab containing the two RadEditor controls, we receive the following Exception caught through Page_Error function:
{"Multiple controls with the same ID '__Page' were found. FindControl requires that controls have unique IDs."

Kindly note that adding one RadEditor to the page always used to work fine for us (may be just one control with '__Page' id). Now we do have to add multiple controls. Please help!

7 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 26 Oct 2009, 09:21 AM
Hi Ami,

You have not sent the full code of  the OnInit handler and we do not know the controlId value.
Our recommendation is to replace RadEditor with a standard <asp:TextBox> control and see whether you will experience the same problem. For some reason the ID attributes of the controls are not set correctly, but this problem is not due to RadEditor.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Zash
Top achievements
Rank 1
answered on 02 Nov 2009, 08:21 PM
Dear Rumen,
    According to your suggestion, I changed the member variable of the above mentioned code to
protected TextBox editor; 

 I have not changed any other existing code except commenting out RadEditor specific properties like
edtor.Html = value; 
    
This time the code ran without any problem and two TextBoxes were correctly displayed in the page. We only get the error while using a RadEditor member variable in the above code. Can you please post a sample code showing how to add two RadEdit's to the sample from code behind (i.e not using <radE:RadEdit> on the aspx page)?

Thank You.
0
Rumen
Telerik team
answered on 05 Nov 2009, 02:19 PM
Hi Ami,

You can try the following code:

private int iCnt = 0;
 
protected void Page_Load(object sender, EventArgs e)
{
}
 
protected void Button1_Click1(object sender, EventArgs e)
{
    AddNewEditor(iCnt);
    iCnt++;
}
 
 
private void AddNewEditor(int id)
{
    RadEditor editor = new RadEditor();
    editor.ID = "Editor" + id;
    form1.Controls.Add(editor);
}
 
protected override void LoadViewState(object savedState)
{
    object[] state = (object[])savedState;
    iCnt = (int)state[0];
 
    for (int i = 0; i < iCnt; i++)
    {
        AddNewEditor(i);
    }
 
    base.LoadViewState(state[1]);
}
 
protected override object SaveViewState()
{
    object[] state = new object[] {
        iCnt,
        base.SaveViewState()
    };
    return state;
}



Regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Zash
Top achievements
Rank 1
answered on 11 Nov 2009, 02:29 PM
Thank you Rumen. It's working now.
0
Steve Williams
Top achievements
Rank 1
answered on 27 Jun 2010, 05:37 PM
You have TextEditorControl inheriting from Page.  You are creating a control.  When you only have one control on the web page, there is no issue inheriting from Page.  When you add the second control, now you have TWO Page base controls.  It seems as if the Page control has some components that it hardcodes to an ID of _Page.  This is not a problem since a web page (aspx) should only have 1 Page control on it.  You now have two.

Change your control to inherit from WebControl.  The reason Rumen's code works is because his code just adds a RadEditor control which, I'm sure, eventually inherits from WebControl and not Page.
0
lbartroli
Top achievements
Rank 1
answered on 14 Jul 2011, 08:41 PM
Rumen, I have the same problem, but I'm working with MVC, can you tell me how to do this in MVC? I want to create dynamically editors from a button.
Thanks ...
0
Rumen
Telerik team
answered on 19 Jul 2011, 03:30 PM
Hi,

RadControls for ASP.NET AJAX do not support Razor view engine of MVC, and for this reason we kindly invite you to test and use our RadControls for ASP.NET MVC Extensions. The suite also offers an MVC editor. If you have any questions about our MVC extensions you can open a support ticket or write in the MVC forums.

Best regards,
Rumen
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Editor
Asked by
Zash
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Zash
Top achievements
Rank 1
Steve Williams
Top achievements
Rank 1
lbartroli
Top achievements
Rank 1
Share this question
or