[英]ASP.NET UserControl with validation
I need to create my UserControl with validation. 我需要创建带有验证的UserControl。 I created UserControl:
我创建了UserControl:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyValidationControl.ascx.cs" Inherits="Labs.MyValidationControl" %>
<asp:Label runat="server" ID="Name">Name</asp:Label> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Field ''Name'' is required." ControlToValidate="TextBox3" ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
<br/>
<asp:Label runat="server" ID="Password">Password</asp:Label><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RangeValidator runat="server" MinimumValue="1" MaximumValue="10" Type="Integer" id="rngText" controltovalidate="TextBox2" ValidationGroup="LoginUserValidationGroup" errormessage="The value must be from 1 to 10!" />
<br />
Then I use UserControl on the form: 然后在表格上使用UserControl:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:MyValidationControl runat="server"/>
</asp:Content>
When I start my application I see nothing on this page. 当我启动我的应用程序时,在此页面上什么也看不到。
I solved this. 我解决了 First, thanks to Kiran1016.
首先,感谢Kiran1016。 He gives me article http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx
他给我文章http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config。 aspx
Second, UserControl must not be in the root directory of the project. 其次,UserControl不能位于项目的根目录中。 I put it in the directory "Controls".
我把它放在目录“控件”中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.