本文介绍了Visual Studio警告“不允许内容”在ASP.NET项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在上个月开始作为程序员工作,所以会有很多新手问题来自我,请继续关注...我现在正在修改提供的模板(从DevExpress)创建新的Web表单,使用Visual Studio 2008上的ASP.NET 2.0。



虽然该Web表单的功能在那里,但我正在摆脱九十个警告消息,大部分他们来自提供的模板。



其中一个让我困惑了一段时间是这样的:
警告75开放和关闭之间不允许内容元素'ClientSideEvents'的标签。



这里是代码:

 < dxe:ASPxListBox id =edtMultiResourcerunat =serverwidth =100%
SelectionMode =CheckColumnDataSource ='<%#ResourceDataSource%>'Border-BorderWidth = 0\" >
< ClientSideEvents SelectedIndexChanged =function(s,e){
var resourceNames = new Array();
var items = s.GetSelectedItems();
var count = items .length;
if(count> 0){
for(var i = 0; i< count; i ++)
_aspxArrayPush(resourceNames,items [i] .text);
$

_aspxArrayPush(resourceNames,ddResource.cp_Caption_ResourceNone);
ddResource.SetValue(resourceNames.join(','));
}>< / ClientSideEvents>
< / dxe:ASPxListBox>

我自己看不到代码有问题,所以请帮我在这里。 p>

解决方案

Chetan Sastry在答案中正确的轨道上被删除。您放入HTML属性的脚本不是HTML编码的。



您必须对HTML中具有特殊含义的任何字符进行编码,如< > & 属性值的分隔符:

 < dxe:ASPxListBox id =edtMultiResourcerunat = serverwidth =100%
SelectionMode =CheckColumnDataSource ='<%#ResourceDataSource%>'Border-BorderWidth =0>
< ClientSideEvents SelectedIndexChanged = (s,e){
var resourceNames = new Array();
var items = s.GetSelectedItems();
var count = items.length;
if(count& gt; 0){
for(var i = 0; i& lt; count; i ++)
_aspxArrayPush(resourceNames,items [i] .text);
}
else
_aspxArrayPush(resourceNames,ddResource.cp_Caption_ResourceNone);
ddResource.SetValue(resourceNames.join(','));
}>< / ClientSideEvents>
< / dxe:ASPxListBox>


I am just started working as a programmer last month, so there will be plenty of newbie question come from me, stay tuned... I am now working on modify the provided template (from DevExpress) to create new web form using ASP.NET 2.0 on Visual Studio 2008.

While the functionality of that web form is there, I am in the process of get rid of ninety something warning message, most of them come from the provided template.

One of them puzzled me for a while is this one:"Warning 75 Content is not allowed between the opening and closing tags for element 'ClientSideEvents'."

And here is the code:

<dxe:ASPxListBox id="edtMultiResource" runat="server" width="100%"
SelectionMode="CheckColumn" DataSource='<%# ResourceDataSource %>' Border-BorderWidth="0">
    <ClientSideEvents SelectedIndexChanged="function(s, e) {
    var resourceNames = new Array();
        var items = s.GetSelectedItems();
        var count = items.length;
        if (count > 0) {
            for(var i=0; i<count; i++)
                _aspxArrayPush(resourceNames, items[i].text);
        }
        else
            _aspxArrayPush(resourceNames, ddResource.cp_Caption_ResourceNone);
        ddResource.SetValue(resourceNames.join(', '));
    }"></ClientSideEvents>
</dxe:ASPxListBox>

I couldn't see anything wrong with the code myself, so please help me out here.

解决方案

Chetan Sastry was on the right track in his answer that he deleted. The script that you have put in the HTML attribute is not HTML encoded.

You have to encode any characters that have a special meaning in HTML, like <, >, & and the " delimiters for the attribute value:

<dxe:ASPxListBox id="edtMultiResource" runat="server" width="100%"
SelectionMode="CheckColumn" DataSource='<%# ResourceDataSource %>' Border-BorderWidth="0">
                                <ClientSideEvents SelectedIndexChanged="function(s, e) {
                                var resourceNames = new Array();
                                    var items = s.GetSelectedItems();
                                    var count = items.length;
                                    if (count &gt; 0) {
                                        for(var i=0; i&lt;count; i++)
                                            _aspxArrayPush(resourceNames, items[i].text);
                                    }
                                    else
                                        _aspxArrayPush(resourceNames, ddResource.cp_Caption_ResourceNone);
                                    ddResource.SetValue(resourceNames.join(', '));
                                }"></ClientSideEvents>
                            </dxe:ASPxListBox>

这篇关于Visual Studio警告“不允许内容”在ASP.NET项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 04:24