Solved

What is wrong with this code declaration?

Posted on 2009-04-01
4
309 Views
Last Modified: 2013-12-25
Could someone please tell me why the vbc (2.0 framework) complains that rptLinks is not declared when in fact it is declared in the repeater statement? I get a similar error in VS 2008.
<%@ 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>

---------------------------------------------

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

Open in new window

0
Comment
Question by:bigmoxy
4 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24044579
Does it work if you wrap the repeater in <form> tags?

<form id="form1" runat="server">

        <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>

</form>

Open in new window

0
 

Author Comment

by:bigmoxy
ID: 24044652
No, I get the same error:

c:\websites\quinceaneragallery.com\Categories.ascx.vb(37) : error BC30451: Name
'rptLinks' is not declared.
0
 
LVL 4

Expert Comment

by:y0usuf
ID: 24049463
There's nothing wrong with the declaration. I know VS2008 shows some carzy messages when they are acctually not. Possibility is there might be some other errors in the page. Are you seeing any other errors along with this?
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
ID: 24049873
Try declaring a member variable 'rptLinks' in the class Categories1:

Partial Class Categories1
  Inherits System.Web.UI.UserControl

    Protected rptLinks As Repeater

...

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now