un RequiredFieldValidator qui requiert pas
Salut
J'ai mis en place des contrôles dans ma page par le CodeBehind. J'ai fait un RequierdFieldValidator et un RegularExpressionValidator et un Bouton.
Lorsque je clique sur le bouton, le RegularExpression marche bien, mais pas le Requierd.
Si je mets les contrôles à la main côté HTML, tout marche bien. Je n'arrive pas à comprendre ce qui fais la différence.
Voici mon CodeBehind
Code:
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 43 44 45 46 47 48 49 50 51 52 53 54
|
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim lblMail As New Label
Dim txtMai As New TextBox
Dim btnEnvoi As New Button
Dim tblContact As New Table
Dim rMail, rBouton As New TableRow
Dim clMail, ctMail, cBouton As New TableCell
Dim revMail As New RegularExpressionValidator
Dim cvMail As New RequiredFieldValidator
lblMail.Text = "Mail "
txtMail.ID = "txtMail"
With btnEnvoi
AddHandler btnEnvoi.Click, AddressOf EnvoiContact
.Text = "Envoyer message"
.ValidationGroup = "ValidMail"
End With
With revMail
.ErrorMessage = "Votre adresse mail ne semble pas correcte"
.ToolTip = "Votre adresse mail ne semble pas correcte"
.ValidationExpression = "^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"
.ControlToValidate = txtMail.ID
.ValidationGroup = "ValidMail"
End With
With cvMail
.ErrorMessage = "Une adresse mail est obligatoire"
.ControlToValidate = txtMail.ID
.ValidationGroup = "ValidMail"
.ToolTip = "Une adresse mail est obligatoire"
End With
clMail.Controls.Add(lblMail)
ctMail.Controls.Add(txtMail)
cBouton.ColumnSpan = 2
cBouton.Controls.Add(btnEnvoi)
cBouton.Controls.Add(revMail)
rMail.Cells.Add(clMail)
rMail.Cells.Add(ctMail)
rBouton.Cells.Add(cBouton)
tblContact.Rows.Add(rMail)
tblContact.Rows.Add(rBouton)
Me.Controls.Add(tblContact)
End Sub
Sub EnvoiContact(ByVal sender As Object, ByVal e As System.EventArgs)
Logage("un contact : " & CType(FindControl("txtMail"), TextBox).Text)
End Sub |
Merci pour votre aide.