2

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?

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • See a previous question I asked and answered myself, I'm thinking it could help : http://stackoverflow.com/questions/15760361/get-and-cast-masterpage-usercontrol-from-content-page-to-access-specific-uc-prop . I didn't make it an answer cause it's c# and not your exact problem, but worth trying as it's quickly done – Laurent S. May 07 '13 at 12:34
  • @Bartdude, I have no idea how that could help in my situation. Can you give me an exact solution, or a hint? – TecMan May 07 '13 at 13:25
  • I was trying to give a hint... My problem was non only on compilation but also in VS. After the changes, VS was able to "see" the public property of my usercontrol, which as I understood is what you're trying to do. – Laurent S. May 07 '13 at 13:30

1 Answers1

2

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
Community
  • 1
  • 1
TecMan
  • 2,743
  • 2
  • 30
  • 64