SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a user control web part and the code behind file contains the following:

using Microsoft.SharePoint;
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;

namespace AnnouncementSlider1.ContentSlider 
public partial class ContentSlider : UserControl
    string Qry = " <Where><Geq><FieldRef Name='Expires' /><Value 
    IncludeTimeValue='FALSE' Type='DateTime'>{0}</Value></Geq></Where>"; 
    protected void Page_Load(object sender, EventArgs e) { 
        if (!IsPostBack) { DisplayAnnouncements(); 
    private void DisplayAnnouncements() { 
            using (SPSite site = new SPSite(SPContext.Current.Site.ID)) 
                using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) 
                    SPList list = web.Lists["Announcements"]; 
                    SPQuery query = new SPQuery(); 
                    query.RowLimit = 10; 
                    query.Query = string.Format(Qry, DateTime.Now.ToString("yyyy-MM-dd")); 
                    rep1.DataSource = list.GetItems(query).GetDataTable(); 

The control has the following item:

    <asp:Repeater ID="rep1" runat="server">             

When I build the solution, I receive an error stating:

Error The name 'rep1' does not exist in the current context

How should I remedy this error?

share|improve this question
Check to see if your .ascx file is valid ie all tags are closed properly. Otherwise are you getting any other errors on build? This is usually the result of something else wrong. – Ryan Erickson Mar 15 '13 at 21:52
All tags are closed in the ascx and no other build errors. – SidC Mar 15 '13 at 21:59
up vote 1 down vote accepted

Stop using RWEP. It is a security risk that you do not need to take. Using the System Account token is sufficient for reading a list.

share|improve this answer

So, I noticed that the ascx was actually under the Control Template folder in the solution for some reason. I re-created the user control and ensured it was saved under the web part folder. This rectified the error.

share|improve this answer

Your Answer


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.