Custom Blog module problem with error message "FindControl requires that controls have unique IDs."

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/16/2010 6:40:26 PM
Gravatar
Total Posts 15

Custom Blog module problem with error message "FindControl requires that controls have unique IDs."

Hi,

I made a copy of the Blog feature and wanted to customize it (make it more simple to use with less fields for the users we're launching this for).  I installed it into my test development environment and am just trying to get it to work first before I made any changes to the existing functionality.  Adding and editing postings, modifying the settings, using the calendar to access the archived blogs, and adding categories work fine.  However, the "Feedback" link, "Categories" and "Archives" link give me an error of the type:

Multiple controls with the same ID 'toyblogarchiveurl' were found. FindControl requires that controls have unique IDs.

where 'toyblogarchiveurl' is a different ID for each link (Feedback, Categories, Archives) that was clicked on.  This particular ID was set in this code for viewing the category postings:

        private void AddConnoicalUrl()
        {
            if (Page.Header == null) { return; }

            Literal link = new Literal();
            link.ID = "toyblogcaturl";
            link.Text = "\n<link rel='canonical' href='"
                + SiteRoot
                + "/TOYBlog/ViewCategory.aspx?cat="
                + categoryId.ToInvariantString()
                + "&amp;mid=" + moduleId.ToInvariantString()
                + "&amp;pageid=" + pageId.ToInvariantString()
                + "' />";

            Page.Header.Controls.Add(link);

        }

Can you tell me what might cause this type of error?  It seems like it's just an ID assigned to a link built on the fly and I've tried to rename these IDs so they don't clash with anything else but can't seem to get rid of the error.  If I click on "Feedback", I get the same type of error but the line it shows for the error is below (and I don't know why, because the layout.master only lists StyleSheetCombiner once so why is it complaining?):

 

Line 134:            StyleSheetCombiner style = Page.Master.FindControl("StyleSheetCombiner") as StyleSheetCombiner;
Line 135:            if (style != null) { style.IncludeGreyBoxCss = true; }

If anyone can shed some light on this, I'd really appreciate it.  I've spent hours trying different things like recopying the Blog module code and hand-typing in the code to see if I can see errors while I'm adding it and can't figure it out.

Thanks!!
7/17/2010 8:11:29 AM
Gravatar
Total Posts 18439

Re: Custom Blog module problem with error message "FindControl requires that controls have unique IDs."

That is strange, if it was a UserControl instead of a page I would guess you had more than one usercontrol instance on the page trying to add the same id.

But, I suspect the error is happening somewhere other than the code that adds the link, because the error seems to be when calling .FindControl and that is not part of the code for adding the literal.

Possibly you are calling the method AddConnoicalUrl more than 1 time.

I would review the rest of your code and step through the code to find out where the error is happening and try commenting things out to find it if needed.

Hope it helps,

Joe

7/26/2010 4:48:24 PM
Gravatar
Total Posts 15

Re: Custom Blog module problem with error message "FindControl requires that controls have unique IDs."

Joe, thanks so much!  I just got back from vacation and thought hard about your comment that the code must be executing more than once.  My experience with issues like this in the past was related to the AutoEventWireup setting so I compared my code against yours and found that the areas that I had problems with had to do with AutoEventWireup set to True as opposed to False, I copied your code file for file but maybe I had inadvertently retyped the directive when I changed the class names and code behind names.  I was comparing the code but usually just skimmed this part, sheesh.  After I changed that setting, those links no longer err.  I owe you a coffee!

You must sign in to post in the forums. This thread is closed to new posts.