IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement Web avec .NET Discussion :

récupérer dynamiquement les éléments d'un controle utilisateur


Sujet :

Développement Web avec .NET

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 2
    Points : 3
    Points
    3
    Par défaut récupérer dynamiquement les éléments d'un controle utilisateur
    Bonjour je développe en C# et par soucis d'amélioration de mon code je voudrais réaliser certaines actions liées à l'utilisation de mon contrôle utilisateur dans une boucle, mais j'ignore comment m'y prendre.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    //Webcontrole.ascx
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="JorgesAppli.WebUserControl1" %>
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
        style="border-collapse: collapse;">
        <tr class="EditFormHeader">
            <td colspan="2">
                <b>Enregistrer un nouveau partenaire</b>
            </td>
        </tr>
        <tr>
            <td>
                <table id="Table3" width="450px" border="0" class="module">
                    <tr>
                        <td>Raison sociale 1:</td>
                         <td>
                             <asp:TextBox ID="TextBox9" Text='<%# Bind( "RaisonSocial") %>' runat="server" TabIndex="8">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Adresse :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox7" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Adresse") %>'>
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Code postal:
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox8" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CodePostal") %>'>' TabIndex="1">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Type partenaire:
                        </td>
                        <td>
                            <telerik:RadDropDownList ID="RadDropDownList1" runat="server" DropDownHeight="200px" Width="226px" Skin="Default"
                                DefaultMessage="Sélectionnez le type de partennaires" DropDownWidth="226px"
                                DataValueField="IdTypePartenaire" DataTextField="Description" DataSourceID="SqlDataSource2" AutoPostBack="true">
                            </telerik:RadDropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <b>SLE :</b>
                        </td>
                    </tr>
                    <tr>
                        <td>Prescription CE :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox2" Text='<%# Bind( "Presription") %>' runat="server" TabIndex="8">
                            </asp:TextBox>
                        </td>
                    </tr>
     
                    <tr>
                        <td>Raison sociale 2:
                        </td>
                        <td>
                             <asp:TextBox ID="TextBox10" Text='<%# Bind( "RaisonSocial2") %>' runat="server" TabIndex="8">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Adresse(2):
                        </td>
                        <td>
                             <asp:TextBox ID="TextBox11" Text='<%# Bind( "Adresse2") %>' runat="server" TabIndex="8">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Ville :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox4" Text='<%# DataBinder.Eval(Container, "DataItem.Commentaires") %>' runat="server" TabIndex="11">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Téléphone :
                        </td>
                        <td>
                            <telerik:RadMaskedTextBox ID="HomePhoneBox" runat="server" SelectionOnFocus="SelectAll"
                                Text='<%# DataBinder.Eval(Container, "DataItem.Telephone") %>' PromptChar="_" Mask="(###) ###-####"
                                TabIndex="3">
                            </telerik:RadMaskedTextBox>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="vertical-align: top">
                <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
                    <tr>
                        <td>Commentaires :
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="TextBox1" Text='<%# DataBinder.Eval(Container, "DataItem.Commentaires") %>' runat="server" TextMode="MultiLine"
                                Rows="5" Columns="40" TabIndex="5">
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Groupe :
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="TextBox6" Text='<%# DataBinder.Eval(Container, "DataItem.Groupe") %>' runat="server" TextMode="MultiLine"
                                Rows="2" Columns="40" TabIndex="6">
                            </asp:TextBox>
                        </td>
                    </tr>
     
                     <tr>
                        <td>Nombre de Kms :
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="TextBox5" Text='<%# DataBinder.Eval(Container, "DataItem.NombreDeKm") %>' runat="server" TextMode="MultiLine"
                                Rows="2" Columns="40" TabIndex="6">
                            </asp:TextBox>
                        </td>
                    </tr>
     
     
                     <tr>
                        <td>Actif  :
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList1" runat="server" TabIndex="2" RepeatDirection="Horizontal" BorderStyle="None" Width="191px">
                                        <asp:ListItem Text="Oui" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Non"></asp:ListItem>
                                    </asp:RadioButtonList>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2"></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td align="right" colspan="2">
                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                            CommandName="Cancel"></asp:Button>
            </td>
        </tr>
    </table>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data Source=CDEV01;Initial Catalog=test;Integrated Security=True" SelectCommand="SELECT * FROM TypePartenaire" />
     
     
    et dans une autre page qui s'appelle traitement.aspx je récupère les éléments qui se trouvent sur dans mon contrôle utilisateur. Tout ceci marche bien, mais dans un soucis d'optimisation de mon code j'aimerai savoir s'il n'est pas possible d'utiliser une boucle pour faire le travail, et si oui comment.
     
     
    //Traitement.aspx
     
    newValues["RaisonSocial"] = (userControl.FindControl("TextBox9") as TextBox).Text;
                            newValues["Adresse"] = (userControl.FindControl("TextBox7") as TextBox).Text;
                            newValues["CodePostal"] = (userControl.FindControl("TextBox8") as TextBox).Text;
                            newValues["Presription"] = (userControl.FindControl("TextBox2") as TextBox).Text;
                            newValues["RaisonSocial2"] = (userControl.FindControl("TextBox10") as TextBox).Text;
                            newValues["Adresse2"] = (userControl.FindControl("TextBox11") as TextBox).Text;
                            newValues["Ville"] = (userControl.FindControl("TextBox4") as TextBox).Text;
                            newValues["Commentaires"] = (userControl.FindControl("TextBox1") as TextBox).Text;
                            newValues["NombreDeKm"] = (userControl.FindControl("TextBox5") as TextBox).Text;
                            newValues["Groupe"] = (userControl.FindControl("TextBox6") as TextBox).Text;
                            newValues["Telephone"] = (userControl.FindControl("HomePhoneBox") as RadMaskedTextBox).Text;
                            newValues["IdTypePartenaire"] = (userControl.FindControl("RadDropDownList1") as RadDropDownList).SelectedValue;
                            //Affectation des dites valeurs
                            String RaisonSocial = (String)newValues["RaisonSocial"];
                            String Adresse = (String)newValues["Adresse"];
                            String Presription = (String)newValues["Presription"];
                            String RaisonSocial2 = (String)newValues["RaisonSocial2"];
                            int CodePostal = int.Parse(newValues["CodePostal"].ToString());
                            int IdTypePartenaire = int.Parse(newValues["IdTypePartenaire"].ToString());
                            String Adresse2 = (String)newValues["Adresse2"];
                            String Ville = (String)newValues["Ville"];
                            String Commentaires = (String)newValues["Commentaires"];
                            String NombreDeKm = (String)newValues["NombreDeKm"];
                            String Groupe = (String)newValues["Groupe"];
                            String Telephone = (String)newValues["Telephone"];

  2. #2
    Membre averti

    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    176
    Détails du profil
    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 176
    Points : 310
    Points
    310
    Par défaut
    Euh, désolé, je serai ravi de t'aider mais je ne comprends pas ce que tu veux faire...

    "je voudrais réaliser certaines actions liées à l'utilisation de mon contrôle", qu'est-on sensé comprendre ?

Discussions similaires

  1. [2.x] Charger dynamiquement les éléments d'un menu dans un layout
    Par Jiraiya42 dans le forum Symfony
    Réponses: 1
    Dernier message: 28/08/2011, 23h51
  2. Récupérer tous les éléments selectionnés d'un select multiple
    Par xillibit dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 08/01/2010, 18h52
  3. bug sur les linkbutton dans un controle utilisateur web
    Par agnes huchon dans le forum ASP.NET
    Réponses: 9
    Dernier message: 20/03/2009, 10h02
  4. Réponses: 6
    Dernier message: 04/06/2008, 17h21
  5. Récupérer tous les éléments d'un JTree
    Par barbiche dans le forum Composants
    Réponses: 3
    Dernier message: 14/12/2007, 03h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo