在ValidationSummary控件之后删除<p> </p>标记

时间:2011-03-22 07:57:51

标签: asp.net visual-studio visual-studio-2010 design-time

我在ASP.NET中使用Visual Studio 2010,后面有C#代码。

我在源视图中有一个包含代码的ASP.NET页面:

<p>
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</p>

如果我切换设计视图并返回VS中的源视图,它会意外地自动删除最后一个</p>

Visual Studio中是否存在同样的问题? 任何想法如何解决?

感谢。

P.S。这是我的完整代码:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h1>
        Create Groups Types</h1>
    <p>
        <asp:DetailsView ID="uxCreateGroupsTypesDisplayer" runat="server" AutoGenerateRows="False"
            DataKeyNames="GroupTypeId" DataSourceID="uxEntityDataSourceCreateGroupsTypes"
            DefaultMode="Insert" 
            oniteminserted="uxCreateGroupsTypesDisplayer_ItemInserted" 
            oniteminserting="uxCreateGroupsTypesDisplayer_ItemInserting">
            <Fields>
                <asp:TemplateField HeaderText="TypeGroup" SortExpression="TypeGroup">
                    <InsertItemTemplate>
                        <asp:TextBox ID="uxTypeGroupInput" runat="server" Text='<%# Bind("TypeGroup") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="TypeGroup field is required."
                            ControlToValidate="uxTypeGroupInput" Text="*">
                        </asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="uxRegularExpressionTypeGroup" runat="server"
                            ControlToValidate="uxTypeGroupInput" ErrorMessage="TypeGroup is too long or short. Change the field accordingly."
                            ValidationExpression="^.{4,40}$">*</asp:RegularExpressionValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Summary" SortExpression="Summary">
                    <InsertItemTemplate>
                        <asp:TextBox ID="uxSummaryInput" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidatorSummary" runat="server" ErrorMessage="Summary field is required."
                            ControlToValidate="uxSummaryInput" Text="*">
                        </asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="uxRegularExpressionSummary" runat="server" ControlToValidate="uxSummaryInput"
                            ErrorMessage="Summary is too long or short. Change the field accordingly." ValidationExpression="^.{4,256}$">*</asp:RegularExpressionValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
    </p>
    <p>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" /></p> <!-- The problem is here - This tag disappear if you switch from source view to design view and back to source view -->
        <asp:EntityDataSource ID="uxEntityDataSourceCreateGroupsTypes" runat="server" 
            EnableFlattening="False"
            EnableInsert="True" EntitySetName="CmsGroupsTypes">
        </asp:EntityDataSource>
</asp:Content>

2 个答案:

答案 0 :(得分:1)

不要使用“设计视图”来编辑标记,请始终使用“源视图”,即标记自身以编辑标记。

IMO Design只是一个简单的,只读的,验证目的的视图。

答案 1 :(得分:1)

在VS2008中,替换为:

<p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" /></p>

使用:

<p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"></asp:ValidationSummary></p>

这有效,但与标记中的结束标记不一致。尽管在IE8中渲染是正确的。

为什么需要将此摘要控件括在段落标记中?验证摘要呈现为块元素。