简体   繁体   中英

ASP.NET UserControl with validation

I need to create my UserControl with validation. I created 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:

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

Second, UserControl must not be in the root directory of the project. I put it in the directory "Controls".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM