【问题标题】:ASP.NET UserControl with validation带有验证的 ASP.NET UserControl
【发布时间】:2013-01-22 09:18:58
【问题描述】:

我需要创建带有验证的 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>

当我启动我的应用程序时,我在此页面上什么也看不到。

【问题讨论】:

  • 当您尝试提交无效值时会发生什么?
  • 你是如何触发这个验证的?如果它是一个按钮你是否为按钮设置了正确的验证组?
  • 问题不在验证中。表格上什么都没有
  • 页面中添加用户控件引用了吗?
  • 你能显示那个 Usercontrol 注册表代码吗?

标签: c# asp.net user-controls


【解决方案1】:

我解决了这个问题。 首先,感谢 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”目录下。

【讨论】:

    猜你喜欢
    • 2011-05-05
    • 1970-01-01
    • 2011-04-12
    • 2013-02-09
    • 2017-02-21
    • 2010-09-28
    • 1970-01-01
    • 2011-06-08
    • 2020-10-08
    相关资源
    最近更新 更多