Sharepoint 2010 Site Page with User Control = Blank Page

89 views Asked by At

I have a problem with a site definition, it has several site pages, in those pages i need to have a top menu, so i created a user control, that draw that menu, and added it to the pages.

After deploying the solution i can create the site just fine.

In the initial phase, i have hard coded values for the menu links, and in each of the pages i could see the menu. Now the menu it's dynamic, so i have a sharepoint list with the menu options, so i changed the code, instead of hard-coded values, i get them from a list, the code runs fine, i can check that while debugging, but in the end i get a complete blank page.

I can't interact with sharepoint data inside a user control that will be used in a site page?

I tested the control in a normal/application page and it works just fine, in both cases (hard-coded and sharepoint data).

A simple sample of the code:

 protected void Page_Load(object sender, EventArgs e)
    {

        lblDate.Text = DateTime.Now.ToLongTimeString();
        ddlData.Items.Clear();

        //Option Manual - WORKS FINE
        ddlData.Items.Add("Manual 1");
        ddlData.Items.Add("Manual 2");
        ddlData.Items.Add("Manual 3");

        //Option Sharepoint Data - DOESNT WORK
        SPSecurity.RunWithElevatedPrivileges(delegate () {
            using (SPSite site = SPContext.Current.Site)
            {
                using (SPWeb web = site.RootWeb)
                {
                    foreach (SPList lista in web.Lists)
                    {
                        ddlData.Items.Add(lista.Title);
                    }

                }
            }
        });

    }

The rest of the code, it's a simple page with the reference to this user control, and the aspx code of the user control only have the declaration of this two controls.

1

There are 1 answers

0
MckPT On

After several tests, i came to conclusion that i have two problems: 1 - In this project for some reason, unknown to me, inside the code someone had added some code to clear the errors, that's why i had the blank page.

2 - After seeing the error, i could confirm that if i use site pages and trying to get the data with Using, when it tries to dispose the objects it throws the exception, so the solution was simple, just remove the Usings.

Thanks