1 pièce(s) jointe(s)
masquer textbox avec bouton
Bonjour,
je rencontre un problème pour une chose qui me parait pourtant plutôt simple à réaliser, voici mon problème :
j'ai un formulaire de contact contenant différentes textbox (nom, prénom, civilité ...) accompagné donc d'un bouton enregistrer mais aussi d'un bouton "+1 contact" signifiant ajouter un contact, lorsque je clic sur ce bouton un second formulaire identique au premier apparait ainsi qu'un autre bouton "-1 contact" permettant de supprimer ce second formulaire, donc si je clic sur ce bouton mon formulaire disparait, alors que si je clic une nouvelle fois sur le bouton "+1 contact" un troisième (et dernier) formulaire apparait, le bouton "+1 contact" quand à lui disparait, je peut donc enregistrer un, deux ou trois formulaire de contact (seul le premier est obligatoire), j'ai ajouté une image en pièce jointe pour vous aider à visualiser.
Voici mon problème : Lorsque les formulaires 2 et 3 reste vide je n'en ai aucun je peut les ajouter/supprimer (visible/non visible) autant de fois que je le souhaite sans problème, mais lorsqu'un des deux contient du texte la je rencontre des problèmes divers et variées :
je vous montre mon code :
asp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="contenu_cadre">
<asp:Panel ID="Panel_contact" runat="server">
<table class="tab_contact">
<tr>
<td style="text-align:center;padding-bottom:10px;">
<asp:Label ID="lbl_contact2" runat="server" Text="Contact 2" Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txt_nom2_contact" runat="server" CssClass="txt_tab_contact" MaxLength="50" Visible="False"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel> |
je vous ai mis qu'un extrait histoire de voir qu'il été placé à l'intérieur d'un update panel.
vb.net
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
Protected Sub bt_ajout_contact1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_ajout_contact1.Click
' on affiche le bouton - 1 contact
bt_supp_contact1.Visible = True
' si le contact2 n'est pas encore affiché alors on l'affiche, sinon on affiche le contact3 et on cache alors le bouton +1 contact
If txt_nom2_contact.Visible = False Then
txt_nom2_contact.Visible = True
txt_prenom2_contact.Visible = True
ddl_civ2_contact.Visible = True
txt_fonction2_contact.Visible = True
txt_tel_fix2_contact.Visible = True
txt_tel_mobile2_contact.Visible = True
txt_email2_contact.Visible = True
lbl_contact2.Visible = True
Else
txt_nom3_contact.Visible = True
txt_prenom3_contact.Visible = True
ddl_civ3_contact.Visible = True
txt_fonction3_contact.Visible = True
txt_tel_fix3_contact.Visible = True
txt_tel_mobile3_contact.Visible = True
txt_email3_contact.Visible = True
lbl_contact3.Visible = True
bt_ajout_contact1.Visible = False
End If
End Sub
Protected Sub bt_supp_contact1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_supp_contact1.Click
' on affiche le bouton + 1 contact s'il ne l'ait pas déjà
bt_ajout_contact1.Visible = True
' si seulement contact2 est visible
If txt_nom3_contact.Visible = False And txt_nom2_contact.Visible = True Then
' si toutes les box sont vides alors on les caches
If txt_nom2_contact.Text = "" And txt_prenom2_contact.Text = "" And ddl_civ2_contact.SelectedValue = "" And txt_fonction2_contact.Text = "" And txt_tel_fix2_contact.Text = "" And txt_tel_mobile2_contact.Text = "" And txt_email2_contact.Text = "" Then
txt_nom2_contact.Visible = False
txt_prenom2_contact.Visible = False
ddl_civ2_contact.Visible = False
txt_fonction2_contact.Visible = False
txt_tel_fix2_contact.Visible = False
txt_tel_mobile2_contact.Visible = False
txt_email2_contact.Visible = False
lbl_contact2.Visible = False
bt_supp_contact1.Visible = False
' si au moins une des box n'est pas vide, alors on affiche un message de confirmation
Else
bt_supp_contact1.OnClientClick = "Confirm(2)"
Dim confirmValue As String = Request.Form("confirm_value")
' si l'utilisateur confirme alors on raz les box et on les caches
If confirmValue = "Ok" Then
txt_nom2_contact.Text = ""
txt_prenom2_contact.Text = ""
ddl_civ2_contact.Text = ""
txt_fonction2_contact.Text = ""
txt_tel_fix2_contact.Text = ""
txt_tel_mobile2_contact.Text = ""
txt_email2_contact.Text = ""
txt_nom2_contact.Visible = False
txt_prenom2_contact.Visible = False
ddl_civ2_contact.Visible = False
txt_fonction2_contact.Visible = False
txt_tel_fix2_contact.Visible = False
txt_tel_mobile2_contact.Visible = False
txt_email2_contact.Visible = False
lbl_contact2.Visible = False
bt_supp_contact1.Visible = False
' si l'utilisateur annule alors on ne fait rien
Else
txt_nom2_contact.Visible = True
txt_prenom2_contact.Visible = True
ddl_civ2_contact.Visible = True
txt_fonction2_contact.Visible = True
txt_tel_fix2_contact.Visible = True
txt_tel_mobile2_contact.Visible = True
txt_email2_contact.Visible = True
lbl_contact2.Visible = True
bt_supp_contact1.Visible = True
End If
End If
' si contact3 est visible lui aussi
Else
' si toutes les box de contact3 sont vides alors on les caches
If txt_nom3_contact.Text = "" And txt_prenom3_contact.Text = "" And ddl_civ3_contact.SelectedValue = "" And txt_fonction3_contact.Text = "" And txt_tel_fix3_contact.Text = "" And txt_tel_mobile3_contact.Text = "" And txt_email3_contact.Text = "" Then
txt_nom3_contact.Visible = False
txt_prenom3_contact.Visible = False
ddl_civ3_contact.Visible = False
txt_fonction3_contact.Visible = False
txt_tel_fix3_contact.Visible = False
txt_tel_mobile3_contact.Visible = False
lbl_contact3.Visible = False
txt_email3_contact.Visible = False
' si au moins une des box n'est pas vide, alors on affiche un message de confirmation
Else
bt_supp_contact1.OnClientClick = "Confirm(3)"
Dim confirmValue As String = Request.Form("confirm_value")
' si l'utilisateur confirme alors on raz les box de contact3 et on les caches
If confirmValue = "Ok" Then
txt_nom3_contact.Text = ""
txt_prenom3_contact.Text = ""
ddl_civ3_contact.Text = ""
txt_fonction3_contact.Text = ""
txt_tel_fix3_contact.Text = ""
txt_tel_mobile3_contact.Text = ""
txt_email3_contact.Text = ""
txt_nom3_contact.Visible = False
txt_prenom3_contact.Visible = False
ddl_civ3_contact.Visible = False
txt_fonction3_contact.Visible = False
txt_tel_fix3_contact.Visible = False
txt_tel_mobile3_contact.Visible = False
lbl_contact3.Visible = False
txt_email3_contact.Visible = False
' si l'utilisateur annule alors on ne fait rien
Else
txt_nom3_contact.Visible = True
txt_prenom3_contact.Visible = True
ddl_civ3_contact.Visible = True
txt_fonction3_contact.Visible = True
txt_tel_fix3_contact.Visible = True
txt_tel_mobile3_contact.Visible = True
txt_email3_contact.Visible = True
lbl_contact3.Visible = True
bt_supp_contact1.Visible = True
End If
End If
End If
End Sub |
donc selon les circonstance j'affiche ou non les différents contrôles, lorsque l'utilisateur clic sur le bouton "-1 contact" alors qu'au moins une textbox à été remplit (donc c'est à partir de ce moment la que commence les non-cohérence) on affiche un popup en javascript afin de lui demander s'il est sur de vouloir confirmer son choix, la première fois il ne se passe rien, il faut cliquer deux fois sur le bouton pour qu'apparaisse cette fenêtre, ensuite le choix que fait l'utilisateur (Ok ou Annuler) n'est pas toujours appliqué, au bout du deuxième essai un seul clic suffit pour afficher la fenêtre mais lors de la confirmation rien ne ce passe... et parfois lorsque les 3 formulaires sont affichés il y a comme "en retard" sur les visibilités des textbox (qui doivent toujours contenir visible=false alors qu'elle sont visible) car il m'affiche le message pour le contact2 alors que le 3 est visible ... voici la fonction en
javascript :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <script type = "text/javascript">
function Confirm(num)
{
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Etes vous sur de vouloir supprimer le contact numéro " + num + ""))
{
confirm_value.value = "Ok";
}
else
{
confirm_value.value = "Annuler";
}
document.forms[0].appendChild(confirm_value);
}
</script> |
voilà, j'attends votre aide pour trouver l'erreur ou éventuellement une autre façon de faire qui donnerai le résultat voulu, merci à vous.