Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom user control which is a "subscribe form". The user enters name, email etc and selects values from dropdowns I data bind from lists. I can view the page no problem and use the form but if I try to edit a page with the user control and then publish it I get the "This page contains content that is not valid. You can find more information in the affected sections."

code:

   private void DataBindDropdowns()
    {
                string siteUrl = SPContext.Current.Site.Url;
                using (SPSite oSiteCollection = new SPSite(siteUrl))
                {
                    using (SPWeb oWebsite = oSiteCollection.OpenWeb())
                    {
                        //Bind the Title (Mr/Mrs/..) dropdown
                        SPList titleList = oWebsite.Lists[Constants.ListNames.SubscribeFormTitles];
                        if (titleList != null)
                        {
                            List<ListItem> source = new List<ListItem>();
                            source.Add(new ListItem("Please select", "Please select"));
                            source.AddRange(titleList.Items.Cast<SPListItem>()
                                .Select(pa => new ListItem(pa.Title, pa.Title))
                                .OrderBy(pa => pa.Text));
                            ddlTitles.DataSource = source;
                            ddlTitles.DataBind();
                        }

                        SPList interestList = oWebsite.Lists[Constants.ListNames.SubscribeFormInterest];
                        if (interestList != null)
                        {
                            var collListItems = from i in interestList.Items.Cast<SPListItem>()
                                                where i[SPBuiltInFieldId.Title] != null
                                                orderby i[SPBuiltInFieldId.Title]
                                                select i;
                            chkInterest.DataSource = collListItems;
                            chkInterest.DataBind();
                        }

                        SPList formTextList = oWebsite.Lists[Constants.ListNames.SubscribeFormText];
                        if (formTextList != null)
                        {
                            var collListItems = formTextList.Items.Cast<SPListItem>();
                            ltTop.Text = collListItems.First()[Constants.FieldNames.TopText].ToString();
                            ltBottom.Text = collListItems.First()[Constants.FieldNames.BottomText].ToString();
                            SubscribeFormTitle.InnerText = collListItems.First().Title.ToString();
                        }
                    }
                }
    }

Is there anything obvious in the code that can cause this problem?

Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You might be using validation controls for name, email etc .If so, Use Validation group so that validation happens only on the button click of user control.

share|improve this answer
    
I already figured out the problem and you're correct. I also don't need to display the user control in edit mode so I put it in an editmodepanel with attribute PageDisplayMode="Display" –  John Dec 2 '11 at 3:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.