问题
We have ascx user controls written in VB.NET for an ASP.NET 4.0 project. The built-in VS page validator always displays the message from the question for all custom properties of our user control.
For instance, here is the beginning of the code of one of our controls:
<%@ Control Language="VB" ClassName="PicView" %>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
Public ImageUrl As String
When we try to use this control using code like this
<%@ Register TagPrefix="foo" TagName="PicView" src="~/ascx/PicView.ascx" %>
<foo:PicView ImageUrl="screenshots/image.gif" runat="server" />
, the "Error List" pane displays this message:
Attribute 'ImageUrl' is not a valid attribute of element 'PicView'
The property works fine in compiled aspx pages, but how to get rid of this in the VS IDE? And enable IntelliSense for such properties if it's possible?
回答1:
Got answer here:
ImageUrl
needs to be a property, rather than a field, for example:
Public Property ImageUrl As String
Get
Return _imageUrl
End Get
Set(value As String)
_imageUrl = value
End Set
End Property
Private _imageUrl As String
来源:https://stackoverflow.com/questions/16419071/asp-net-validation-message-attribute-is-not-a-valid-attribute-of-element