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?

  • 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. Mar 15, 2013 at 21:52
  • All tags are closed in the ascx and no other build errors.
    – SidC
    Mar 15, 2013 at 21:59

2 Answers 2


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.



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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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