如何在VS ASPX逃跑ASP.NET验证? [英] How to run off ASP.NET validation for aspx in VS?

查看:111
本文介绍了如何在VS ASPX逃跑ASP.NET验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经典的ASP.NET 4.0项目命名为PicView一个ascx控件。它的开头是这样的:

 <脚本=服务器>
公众的ImageUrl作为字符串

,这意味着我们可以在aspx页面使用控件的ImageUrl属性。要使用该控件,我下面的指令添加到aspx页面:

 <%@注册标签preFIX =X变量名=PicViewSRC =〜/ ASCX / PicView.ascx%GT;

,再后来在ASPX体使用这样的控件:

 < X:PicView的ImageUrl =IMG / BLA-bla.jpg=服务器/>

但是,Visual Studio中的自动内置ASP.NET验证始终报告以下问题:


  

验证(ASP.Net):属性的ImageUrl'不是元素的有效属性PicView

我得到吨这些警告消息对我的现实世界中的项目。我没有设法做任何可能帮助VS明白我的code是正确的,所以我不知道有没有办法把这个验证了吗?

请注意,我需要仅关闭ASP.NET验证,而不是该项目的特定HTML版本验证。当然,如果你能告诉我如何使这个验证我的情况下工作,这将是非常好的。


解决方案

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

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

如果您希望能够修改code的财产,并将它坚持跨回传,你应该使用ViewState中存储其值,例如:

 公共财产的ImageUrl作为字符串
    得到
        返回的ViewState(图片网址)
    到底得的
    设置(值作为字符串)
        ViewState中(图片网址)=值
    结束设定
高端物业

I have an ascx control named PicView in a classic ASP.NET 4.0 project. The beginning of it looks like this:

<script runat="server">
Public ImageUrl As String

, meaning that we can use the control's ImageUrl property in aspx pages. To use the control, I add the following directive to an aspx page:

<%@ Register TagPrefix="x" TagName="PicView" src="~/ascx/PicView.ascx" %>

, and then later in the body of the aspx use the control like this:

<x:PicView ImageUrl="img/bla-bla.jpg" runat="server" />

However, Visual Studio's automatic built-in ASP.NET validation always reports the following problem:

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

I get tons of these warning messages for my real-world project. I have not managed to do anything that could help VS to understand that my code is correct, so I wonder is there a way to turn this validation off?

Note that I need to turn off only the ASP.NET validation, but not the specific HTML version validation for this project. Sure, if you can tell me how to make this validation working in my situation, it would be very nice.

解决方案

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

If you want to be able to modify the property in code, and have it persisted across a PostBack, you should use ViewState to store its value, e.g.:

Public Property ImageUrl As String
    Get
        Return ViewState("imageUrl")
    End Get
    Set(value As String)
        ViewState("imageUrl") = value
    End Set
End Property

这篇关于如何在VS ASPX逃跑ASP.NET验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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