简体   繁体   中英

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 .

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.

确保您的标签的变量名称是norecoreds,只需单击on标签并查看标签的属性,尤其是名称

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

    }
}

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM