0

検証を使用して 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 />

次に、フォームで UserControl を使用します。

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">

    <asp:MyValidationControl runat="server"/>
</asp:Content>

アプリケーションを起動すると、このページには何も表示されません。

4

1 に答える 1

0

私はこれを解決しました。まず、Kiran1016に感謝します。彼は私に記事http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-configをくれます。 aspx

次に、UserControlはプロジェクトのルートディレクトリに存在してはなりません。「Controls」ディレクトリに置きました。

于 2013-01-22T11:13:43.233 に答える