簡體   English   中英

帶有驗證的ASP.NET UserControl

[英]ASP.NET UserControl with validation

我需要創建帶有驗證的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>

當我啟動我的應用程序時,在此頁面上什么也看不到。

我解決了 首先,感謝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不能位於項目的根目錄中。 我把它放在目錄“控件”中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM