ASP.NET validation message “Attribute … is not a valid attribute of element …” for user control

Deadly 提交于 2019-12-11 06:46:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!