Neha Raje
Neha Raje

Reputation: 357

Label id not declared error in VB.NET

I have a simple label in ASP.NET. I want to set text to it in VB.NET. The id for the label is norecords. The VB.NET code is like this: lblnorecords.Text = "No Record found".

However, it gives me error saying: name norecord is not declared.

Upvotes: 1

Views: 7309

Answers (6)

Quagis
Quagis

Reputation: 1

I had this problem too. After closing and re-opening Visual Studio the variable was recognized, so try restarting your design environment.

Upvotes: -1

KHALID
KHALID

Reputation: 87

if you get error same this is not declared. It may be inaccessible due to its protection level.
Change The Control Property : GenerateMember = True

Only change the property

Upvotes: 1

Renlo
Renlo

Reputation: 11

I had the same problem.

A radio button list, doesnt work well. and show that "name norecord is not declared".

Probably you have two aspx with the same name or similare name, and the lengauge doesn't kwon what page is the owner of this control.

By example y had two page with similar name page.aspx and page1.aspx and both of them were incluide in teh proyect, I exclude one of the project and all work well.

Check that.

Upvotes: 1

Van
Van

Reputation: 21

Sometimes the name has not been registered to the .aspx.designer.vb file, which causes the problem because codebehind gets the naming info from that file. You can easily see that by using intellisense in the codebehind, and see if the variable name exists. If it did not register it's a VS bug .

Click back and forth in .aspx a few times from source to design, and see if the name was now correctly registered in the .aspx.designer.vb file. If not, change manually.

Upvotes: 2

chprpipr
chprpipr

Reputation: 2039

If you label is inside some sort of template, its not available directly in the page scope. Here's a rough example of how you might access it:

MyPage.aspx

<asp:Repeater ID="repGeneric" runat="server" OnItemDataBound="RepGenericItemDataBound">
<ItemTemplate>

    <asp:Label ID="lblnorecords" runat="server" CssClass="separateYourCss" />

</ItemTemplate>
</asp:Repeater>

MyPage.aspx.cs

...
protected void RepGenericItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item 
        || e.Item.ItemType == ListItemType.AlternatingItem) {

        var myLabel = e.Item.FindControl("lblnorecords");

        myLabel.Text = "No Records Found";

    }
}

Upvotes: 1

Troydm
Troydm

Reputation: 2680

Make sure that's your label's variable name is norecoreds, just click on the on label and see properties of the label, especially name

Upvotes: 1

Related Questions