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

8 posts, 0 answers
  1. Zash
    Zash avatar
    40 posts
    Member since:
    Aug 2005

    Posted 21 Oct 2009 Link to this post

    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!
  2. Rumen
    Admin
    Rumen avatar
    14100 posts

    Posted 26 Oct 2009 Link to this post

    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.
  3. Zash
    Zash avatar
    40 posts
    Member since:
    Aug 2005

    Posted 02 Nov 2009 Link to this post

    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.
  4. Rumen
    Admin
    Rumen avatar
    14100 posts

    Posted 05 Nov 2009 Link to this post

    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.
  5. Zash
    Zash avatar
    40 posts
    Member since:
    Aug 2005

    Posted 11 Nov 2009 Link to this post

    Thank you Rumen. It's working now.
  6. Steve Williams
    Steve Williams avatar
    2 posts
    Member since:
    Mar 2010

    Posted 27 Jun 2010 Link to this post

    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.
  7. lbartroli
    lbartroli avatar
    7 posts
    Member since:
    Jun 2011

    Posted 14 Jul 2011 Link to this post

    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 ...
  8. Rumen
    Admin
    Rumen avatar
    14100 posts

    Posted 19 Jul 2011 Link to this post

    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!

Back to Top