powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Validating Custom User Control
3 сообщений из 3, страница 1 из 1
Validating Custom User Control
    #34043034
oldbam
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
hi! I have a user control, which consists of a label and a text box. I want to make validation of my user control with standard asp.net validators. I write the following:



[System.Web.UI.ValidationPropertyAttribute("TextBoxValidation")]

public class MyUserControl : System.Web.UI.UserControl

{

public string TextBoxValidation

{

get {}

set {}

}

The question is:


What should be written in the TextBoxValidation setter and getter?

Thanks in advance!
...
Рейтинг: 0 / 0
Validating Custom User Control
    #34043088
Фотография vladgrig
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Привет из центра! Апельсины будем грузить бочками...
Hi! I wrote some code for You! It's written on VB.NET for FW 2.0 but I hope you can translate this on C#...
Here is it:
UserControl
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
<%@ Control Language="VB" ClassName="WebUserControl" %>

<script runat="server">
    
    Public WriteOnly Property ValidationExpression() As String
        Set(ByVal value As String)
            RegularExpressionValidator1.ValidationExpression = value
        End Set
    End Property
    
    Protected _ValidationGroup As String = ""
    Public WriteOnly Property ValidationGroup() As String
        Set(ByVal value As String)
            _ValidationGroup = value
        End Set
    End Property
       
    Public WriteOnly Property ErrorMessageForeColor() As String
        Set(ByVal value As String)
            RegularExpressionValidator1.ForeColor = System.Drawing.Color.FromName(value)
        End Set
    End Property
    
    Public WriteOnly Property ErrorMessage() As String
        Set(ByVal value As String)
            RegularExpressionValidator1.ErrorMessage = value
        End Set
    End Property
    
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox1.Attributes.Add("autocomplete", "off")
        
        If _ValidationGroup <> "" Then
            TextBox1.ValidationGroup = _ValidationGroup
            RegularExpressionValidator1.ValidationGroup = _ValidationGroup
        End If
    End Sub
    
</script>

<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="" ValidationExpression=".*" ControlToValidate="TextBox1" Display="Dynamic" SetFocusOnError="true"></asp:RegularExpressionValidator>
This code from page where You put UserControl:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
<%@ Page Language="VB" %>

<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Me.IsPostBack Then
            Page.Validate()
            If Not (Page.IsValid) Then
                Response.Redirect("Default2.aspx")
            End If
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc2:WebUserControl ID="WebUserControl1" ErrorMessage="* allows only digits!" ErrorMessageForeColor="blue" ValidationExpression="[0-9]{1,}" ValidationGroup="temp" runat="server" />
       <br />
        <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="temp" /></div>
    </form>
</body>
</html>
Best regards!
...
Рейтинг: 0 / 0
Validating Custom User Control
    #34043704
oldbam
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Great thanks! :-)

I hoped to find some info in msdn, but I failed :(.
Could you please provide any reference to the msdn docs about this topic?

Thanks again!
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Validating Custom User Control
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]