删除
ValidationSummary 控件后的标记我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 VS2008 中,替换为:
替换为:
尽管与标记中的结束标记不一致,但该方法有效。虽然在 IE8 中渲染是正确的。
为什么这个摘要控件需要包含在段落标记中?验证摘要呈现为块元素。
In VS2008, replaced:
With:
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.
不要使用设计视图来编辑标记,始终使用源视图,即标记本身来编辑标记。
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.