ASP.NET验证消息"属​​性...不是元素的有效属性..."用户控制 [英] ASP.NET validation message "Attribute ... is not a valid attribute of element ..." for user control

查看:299
本文介绍了ASP.NET验证消息"属​​性...不是元素的有效属性..."用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经写在VB.NET为ASP.NET 4.0项目ASCX用户控件。内置VS页面验证总是显示为我们的用户控件的所有自定义属性从问题的消息。

例如,这里是我们的控件之一的code的开头:

 <%@控制语言=VB类名=PicView%GT;
<%@导入命名空间=System.Drawing中%GT;
<脚本=服务器>
    公众的ImageUrl作为字符串

当我们尝试用code像这样使用此控件

 <%@注册标签preFIX =富变量名=PicViewSRC =〜/ ASCX / PicView.ascx%GT;
<富:PicView的ImageUrl =截图/ Image.gif的=服务器/>

,错误列表窗格中显示如下消息:

属性的ImageUrl'不是元素的有效属性PicView

该物业工作正常编译aspx页面,但如何在VS IDE摆脱呢?并启用这种特性智能感知是否有可能?


解决方案

得到的答案<一个href=\"http://stackoverflow.com/questions/21753237/how-to-run-off-asp-net-validation-for-aspx-in-vs/\">here:

的ImageUrl 需要一个属性,而不是一个字段,例如:

 公共财产的ImageUrl作为字符串
    得到
        返回_imageUrl
    到底得的
    设置(值作为字符串)
        _imageUrl =价值
    结束设定
高端物业
私人_imageUrl作为字符串

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?

解决方案

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

这篇关于ASP.NET验证消息&QUOT;属​​性...不是元素的有效属性...&QUOT;用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆