删除

ValidationSummary 控件后的标记

发布于 2024-10-25 14:51:40 字数 3538 浏览 3 评论 0原文

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

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

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

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

您的 Visual Studio 中是否也遇到同样的问题? 有什么想法如何解决吗?

谢谢。

PS 这是我的完整代码:

<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>

I use Visual Studio 2010 in ASP.NET with C# code behind.

I have an ASP.NET page with code in Source View:

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

If I switch in Design View and come back to Source View in VS, it unexpectedly removes the last </p> automatically.

Do you have the same problem in your Visual Studio?
Any ideas how to solve it?

Thanks.

P.S. Here my full code:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぽ尐不点ル 2024-11-01 14:51:40

在 VS2008 中,替换为:

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

替换为:

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

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

为什么这个摘要控件需要包含在段落标记中?验证摘要呈现为块元素。

In VS2008, replaced:

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

With:

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

This works, although does not agree with the closing tag in markup. Rendering is correct though in IE8.

Why does this summary control need to be enclosed in a paragraph tag? The Validation Summary renders as a block element.

幽蝶幻影 2024-11-01 14:51:40

不要使用设计视图来编辑标记,始终使用源视图,即标记本身来编辑标记。

IMO 设计视图只是一个简单的、只读的、用于验证目的的视图。

Don't use Design View to edit markup, always use Source View, i.e. markup itself to edit markup.

IMO Design View just a simple, read-only, verify-purpose view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文