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

JavaScript Discussion :

Javascript et code behind


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Octobre 2009
    Messages
    54
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 54
    Par défaut Javascript et code behind
    Bonjour,

    je suis bloquée sur mon code et j'aurai besoin d'aide.

    voila j'ouvre une page modale dans laquelle je récupère des données en javascript, dans des champs cachés.
    A la fin de cette récupération, je souhaiterai mettre à jour une dropdownlist à part d'un champ caché. j'ai une fonction C# qui fait ça mais qui se déclenche qu'à partir d'un bouton.
    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
    function recupArgLigne() {
                document.getElementById('HiddenEntete').value = reception.param2;
                switch (reception.param1) {
                    case "NewLigne":
                        {
                            document.getElementById('btnEnregistrerLigne').value = "Ajouter";
                            break;
                        }
                    case "UpdateLigne":
                        {
                            document.getElementById('btnEnregistrerLigne').value = "Modifier";
                            document.getElementById('HiddenLigne').value = reception.param3;
                            document.getElementById('txtTempsMini').value = reception.param4;
                            document.getElementById('txtTempsMaxi').value = reception.param5;
                            document.getElementById('txtObservations').value = reception.param6;
                            document.getElementById('ddlTypeOperation').value = reception.param7;
                            document.getElementById('ddlTypeBain').value = reception.param8;
                            document.getElementById('ddlTache').value = reception.param9;
                            document.getElementById('ddlGroupePgm').value = reception.param10;
                            document.getElementById('ddlTypeEmplacement').value = reception.param11;
                            document.getElementById('HiddenIDLigne').value = reception.param12;
                            document.getElementById('txtRang').value = reception.param13;
                            break;
                        }
                }
           }
    le reste de mon code
    Code html : 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
    <body>
        <form id="formModal" method="post" runat="server">
        <br />
        &nbsp;&nbsp;&nbsp;
        <asp:Image ID="Image1" runat="server" ImageUrl="~/Resources/PCCF-LOGO.BMP" Height="50px"
            Width="85px" />
        <br />
        <br />
        <asp:HiddenField ID="HiddenMode" runat="server" />
        <asp:HiddenField ID="HiddenEntete" runat="server" />
        <asp:HiddenField ID="HiddenLigne" runat="server" />
        <asp:HiddenField ID="HiddenIDLigne" runat="server" />
    <div id="DivLigne">
            <div style="clear: both; float: left; width: 355px; height: 391px;">
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblRang" runat="server" Text="Rang" />
                    </div>
                    <div style="float: right; width: 191px;">
                        <asp:TextBox ID="txtRang" runat="server" TabIndex="1" Style="width: 100%" />
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblTempsMiniLigne" runat="server" Text="Temps mini" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:TextBox ID="txtTempsMini" runat="server" TabIndex="2" Style="width: 100%" />
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblTempsMaxiLigne" runat="server" Text="Temps maxi" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:TextBox ID="txtTempsMaxi" runat="server" TabIndex="3" Style="width: 100%" />
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblObservations" runat="server" Text="Observations" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:TextBox ID="txtObservations" runat="server" TabIndex="4" Style="width: 100%" />
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblTypeOperation" runat="server" Text="Type opération" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:DropDownList ID="ddlTypeOperation" runat="server" TabIndex="5" DataSourceID="sdsTypeOpe"
                            DataTextField="LIB_TYPE_OP" DataValueField="ID_TYPE_OP" Style="width: 100%">
                            <asp:ListItem Value="-1">Sélectionner une valeur</asp:ListItem>
                        </asp:DropDownList>
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblTypeBain" runat="server" Text="Type de bain" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:DropDownList ID="ddlTypeBain" runat="server" TabIndex="6" DataTextField="LIB_TYPE_BAIN"
                            DataValueField="ID_TYPE_BAIN" DataSourceID="sdsTypeBain" Style="width: 100%" />
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblTache" runat="server" Text="Tâche" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:DropDownList ID="ddlTache" runat="server" TabIndex="7" DataSourceID="sdsTache"
                            DataTextField="LIB_TACHE" DataValueField="ID_TACHE" Style="width: 100%">
                            <%--<asp:ListItem Value="-1">Sélectionner une valeur</asp:ListItem>--%>
                        </asp:DropDownList>
                    </div>
                </div>
                <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblGroupeProgramme" runat="server" Text="Groupe programme" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:DropDownList ID="ddlGroupePgm" runat="server" TabIndex="8" DataTextField="LIB_GROUPE_PROG"
                            DataValueField="ID_GROUPE_PROG" DataSourceID="sdsGroupePgm" Style="width: 100%" />
                    </div>
                </div>
                          <div style="clear: both; float: left; width: 320px;">
                    <div style="clear: both; float: left; width: 129px;">
                        <asp:Label ID="lblLigneReference" runat="server" Text="Ligne de référence" />
                    </div>
                    <div style="float: right; width: 191px">
                        <asp:DropDownList ID="ddlIDLigneRef" runat="server" TabIndex="10" DataTextField="RANG_LIGNE_FT"
                            DataValueField="ID_LIGNE_FT" Style="width: 100%">
                            <asp:ListItem Value="-1">Sélectionner une valeur</asp:ListItem>
                        </asp:DropDownList>
                        <%--DataSourceID="sdsIDLigneRef"--%>
                        <asp:Button ID="btnActualiser" Text="..." runat="server" OnClick="btnActualiser_Click" />
                    </div>
                </div>
                <div style="clear: both; float: left; height: 31px; width: 354px;">
                    <br />
                </div>
                <div style="clear: both; float: left; height: 31px; width: 320px;">
                    <asp:Button ID="btnEnregistrerLigne" Text="Enregistrer" runat="server" OnClick="btnEnregistrerLigne_Click"
                        TabIndex="5" />
                    <input type="button" value="Fermer" onclick="fermerFenetre()" tabindex="6" />
                </div>
                <div style="clear: both; float: left; height: 31px; width: 320px;">
                    <asp:Label ID="lblErreurLigne" runat="server" Style="font-weight: 700; color: #FF0000;"></asp:Label>
                    <asp:Label ID="lblOKLigne" runat="server" Style="font-weight: 700; color: #009933;"></asp:Label>
                </div>
            </div>
            <div title="SqlDataSource" style="clear: both; float: left">
                <asp:SqlDataSource ID="sdsTypeOpe" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_TYPE_OP, LIB_TYPE_OP FROM ADMIN.TYPE_OP ORDER BY LIB_TYPE_OP">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsTypeBain" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_TYPE_BAIN, LIB_TYPE_BAIN, MSG_TYPE_BAIN FROM ADMIN.TYPE_BAIN ORDER BY LIB_TYPE_BAIN">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsTypeEmplacement" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_TYPE_EMPL, LIB_TYPE_EMPL FROM ADMIN.TYPE_EMPL ORDER BY LIB_TYPE_EMPL">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsGroupePgm" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_GROUPE_PROG, LIB_GROUPE_PROG, ID_PRGDEF_GROUPE_PROG FROM ADMIN.GROUPE_PROG ORDER BY LIB_GROUPE_PROG">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsTache" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_TACHE, LIB_TACHE, ID_METIER_TACHE, ID_GROUPE_TACHE_TACHE FROM ADMIN.TACHE WHERE (ID_METIER_TACHE = 21) ORDER BY ID_TACHE">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="sdsIDLigneRef" runat="server" ConnectionString="<%$ ConnectionStrings:PCCConnectionStringBDD %>"
                    ProviderName="<%$ ConnectionStrings:PCCConnectionStringBDD.ProviderName %>" SelectCommand="SELECT ID_LIGNE_FT, MINI_LIGNE_FT, MAXI_LIGNE_FT, OBS_LIGNE_FT, RANG_LIGNE_FT, ID_TYPE_OP_LIGNE_FT, ID_TYPE_BAIN_LIGNE_FT, ID_TACHE_LIGNE_FT, ID_GROUPE_PROG_LIGNE_FT, ID_TYPE_EMPL_LIGNE_FT, ID_ENTETE_FT_LIGNE_FT, ID_REF_LIGNE_FT FROM ADMIN.LIGNE_FT WHERE (ID_ENTETE_FT_LIGNE_FT = :monEntete)">
                </asp:SqlDataSource>
            </div>
        </div>
     <script type="text/javascript" language="JavaScript">
            recupArguments() 
        </script>
        </form>
    </body>
    Ma fonction C# est la suivante:
    Code c# : 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
    protected void AffichageLigneRef()
            {
                string monEntete = HiddenEntete.Value;
                sdsIDLigneRef.SelectCommand = "SELECT ID_LIGNE_FT, MINI_LIGNE_FT, MAXI_LIGNE_FT, OBS_LIGNE_FT, RANG_LIGNE_FT, ID_TYPE_OP_LIGNE_FT, ID_TYPE_BAIN_LIGNE_FT, ID_TACHE_LIGNE_FT, ID_GROUPE_PROG_LIGNE_FT, ID_TYPE_EMPL_LIGNE_FT, ID_ENTETE_FT_LIGNE_FT, ID_REF_LIGNE_FT FROM ADMIN.LIGNE_FT WHERE (ID_ENTETE_FT_LIGNE_FT = '" + monEntete + "') ORDER BY RANG_LIGNE_FT";
                try
                {
                    ddlIDLigneRef.DataSource = sdsIDLigneRef;
                    ddlIDLigneRef.Visible = true;
                    ddlIDLigneRef.Items.Clear();
                    ddlIDLigneRef.DataBind();
                    ddlIDLigneRef.Items.Insert(0, "Sélectionner une valeur");
     
                    if (HiddenMode.Value == "UpdateLigne")
                    {
                        ddlIDLigneRef.SelectedIndex = Convert.ToInt32(HiddenIDLigne.Value.ToString());
                    }
                    btnActualiser.Visible = false;
                }
                catch (Exception e1)
                {
                    ddlIDLigneRef.Visible = false;
                }
            }

    Comment faire pour qu'à la fin de l'ouverture de ma page, je puisse lancer ma fonction C#.
    Je sais pas si ma question est clair.

    Merci pour votre aide.
    Sophie

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par défaut
    C#=> coté serveur

    Html js => coté client

    fin de chargement de page = coté client le onlaod du body

    il te faudra donc retourner sur le serveur à la fin du chargement de la page
    regarde du coté d'ajax ...
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  3. #3
    Membre très actif
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations forums :
    Inscription : Août 2010
    Messages : 130
    Par défaut
    Hi!

    Ton body coté client (ajoutes un id):
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <body runat="server" id="masterbody">

    dans le code c# (serveur) ajoutes une reference au body:
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    masterbody.Attributes.Add("onload", "javascript:myFunction();")

    c'est quelque chose comme ca. Sinon tu devrais trouver un moyen d'appeller la bonne méthode C# peut etre au lieu de javascript:myFunction();

  4. #4
    Membre averti
    Inscrit en
    Octobre 2009
    Messages
    54
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 54
    Par défaut Javascript et code behind
    Bonjour merci pour votre aide.

    j'ai essayé la méthode de n2engineer5.

    J'ai ajouté dans ma fonction Page_Load()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    formModal.Attributes.Add("onload","javascript:recupArguments();");
    Ma fonction javascript ne s'exécute pas.

    Peut être qu'il faut que je mette cette instruction ailleurs mais je ne vois pas où.
    Pourriez vous me dire?

    Merci bcp.

  5. #5
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    formModal.Attributes.Add("onload","javascript:recupArguments();");
    En même temps, ta fonction JavaScript s'appelle recupArgLigne()...

    Et au passage si je mets
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    formModal.Attributes.Add("onload","crepeSuzette:recupArguments();");
    Ca me fera des crèpes suzettes ?
    Pour rappel, le pseudoprotocole javascript: est strictement inutile : A quoi sert 'javascript:' dans une balise HTML ?
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  6. #6
    Membre averti
    Inscrit en
    Octobre 2009
    Messages
    54
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 54
    Par défaut Javascript et code behind
    oui ma fonction s'appelle RecupArgligne() (qui est appelé dans recupArguments()).
    Ce que j ecomprend spas c'est pourquoi ça ne fonctionne pas.

    En mettant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    formModal.Attributes.Add("onload", "recupArguments();");
    dans mon page_load pourquoi ça ne lance pas ma fonction javascript.

    il faudrait que ma fonction C# soit lancée à la fin de ma fonction javascript afin que mes données soient dans mes champs cachés. comment puis je faire? (au lieu de lancer le javascript dans mon page_load)

Discussions similaires

  1. Appellé une fonction javascript en code behind
    Par 0xYg3n3 dans le forum ASP.NET
    Réponses: 4
    Dernier message: 17/10/2007, 15h02
  2. JavaScript en code-behind
    Par jf1985 dans le forum C#
    Réponses: 2
    Dernier message: 22/09/2007, 21h33
  3. [tout bête] JavaScript en code behind
    Par dahu17 dans le forum C#
    Réponses: 1
    Dernier message: 06/09/2007, 15h28
  4. Google Map API --> Javascript et code behind C#
    Par bridel dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/01/2007, 21h07
  5. [VB.NET]Javascript et code behind
    Par Dadou74 dans le forum ASP.NET
    Réponses: 1
    Dernier message: 17/11/2006, 16h30

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