Solved

What is wrong with this code declaration?

Posted on 2009-04-01
4
312 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I use SQL Stored Procedure to return FedEx Zone 17 41
SQL Exceptions 3 39
Javascript and Jquery not firing 9 42
VS.net 2010 11 24
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

13 Experts available now in Live!

Get 1:1 Help Now