Is this Visual Studio 2005 ? The presence of the Web form designer generated code seems to suggest otherwise. If it's a VS 2005 website project, you should use the CodeFile attribute instead of the CodeBehind attribute on the @Page directive.
On Apr 2, 4:10 am, Bigmoxy <[email protected]> wrote: > 2.0 framework: > > I have a user control which cannot be compiled. #Region " Web Form > Designer Generated Code " > > c:\websites\quinceaneragallery.com\Categories.ascx.vb(37) : error > BC30451: Name > 'rptLinks' is not declared. > > rptLinks.DataSource = objCommand.ExecuteReader > ~~~~~~~~ > c:\websites\quinceaneragallery.com\Categories.ascx.vb(38) : error > BC30451: Name > 'rptLinks' is not declared. > > rptLinks.DataBind() > ~~~~~~~~ > > Here is the code for the control and the code behind file. Can someone > please tell me why the compiler says that rptLinks is not declared? Is > there a better way to code this control? > > Thank you! > Tim > > Categories.ascx > ------------------------ > <%@ Control Language="vb" AutoEventWireup="false" > Codebehind="Categories.ascx.vb" Inherits="keepsake.Categories1" > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> > <font face="arial" size="2"> > <asp:Repeater ID="rptLinks" Runat="server"> > <ItemTemplate> > <a href='quinceanera.aspx?cat_id=<%# DataBinder.Eval > (Container.DataItem, "cat_id")%>'><%# DataBinder.Eval > (Container.DataItem, "cat_name")%></a><br> > </ItemTemplate> > <FooterTemplate> > <br> > </FooterTemplate> > </asp:Repeater> > </font> > > Categories.ascx.vb > --------------------------- > Imports System.Data.SqlClient > > Namespace keepsake > > Partial Class Categories1 > Inherits System.Web.UI.UserControl > > #Region " Web Form Designer Generated Code " > > 'This call is required by the Web Form Designer. > <System.Diagnostics.DebuggerStepThrough()> Private Sub > InitializeComponent() > > End Sub > > Private Sub Page_Init(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles MyBase.Init > 'CODEGEN: This method call is required by the Web Form > Designer > 'Do not modify it using the code editor. > InitializeComponent() > End Sub > > #End Region > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles MyBase.Load > If (Not Page.IsPostBack) Then > Dim objConn As SqlConnection = New SqlConnection > (System.Configuration.ConfigurationManager.AppSettings > ("ConnectionString")) > Dim objCommand As SqlCommand = New SqlCommand > Dim objReader As SqlDataReader > > objCommand.CommandText = "SELECT * FROM Categories > ORDER BY cat_name" > > objCommand.Connection = objConn > > objConn.Open() > rptLinks.DataSource = objCommand.ExecuteReader > rptLinks.DataBind() > objConn.Close() > > objCommand.Dispose() > objCommand = Nothing > > objConn.Dispose() > objConn = Nothing > End If > End Sub > > End Class > > End Namespace
