Smur
Smur

Reputation: 3113

Suppress Compiler Warning in ASP.NET / VB.NET

The ASP.NET compiler tells me a certain tag does not accept a certain attribute, although it builds, and it renders correctly on the browser. It's a dull warning message.

How can I disable that warning message in certain lines of the ASP.NET code?

The warning pops at this line:

<asp:ListItem Text="" Value="" style="display: none" />

Warning:

Validation (ASP.Net): Attribute 'style' is not a valid attribute of element 'ListItem'.

PS: I just want to disable that warning message for that specified line of code, I don't want to disable it for the whole project. Is there a way to do this?

Upvotes: 2

Views: 1669

Answers (3)

Răzvan Flavius Panda
Răzvan Flavius Panda

Reputation: 22106

You can suppress only certain errors by opening the property page for the project, clicking the build property page and then modify the Suppress Warnings property. Insert the code of the warning you want to suppress there. You can find what is the code of the warning by checking it in the error list.

Upvotes: 1

mellamokb
mellamokb

Reputation: 56769

I don't think you can suppress warnings on aspx code on individual lines because the aspx code is not really processed in a line-by-line manner (it is parsed using an XML-like parser). However, you can get around the warning by setting the style programmatically:

MyListItemControl.Items(0).Attributes("style") = "display:none;"

Upvotes: 2

Paige Cook
Paige Cook

Reputation: 22555

In Visual Studio select the menu item Tools->Options... Then select Text Editor->HTML->Validation. To disable the compiler warnings uncheck the Show errors as warnings option for all applicable HTML Target types.

Upvotes: 0

Related Questions