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

ASP.NET Discussion :

WebControl : texte généré pas au bon endroit


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    262
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 262
    Par défaut WebControl : texte généré pas au bon endroit
    bonjour, j'ai fait un webcontrol :
    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
    using System;
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace Classes.WebControls
    {
        /// <summary>
        /// Desciription de wbcFlash
        /// WebControl servant à l'intégration d'élément Flash
        /// </summary>
        [AspNetHostingPermission(SecurityAction.Demand,
        Level = AspNetHostingPermissionLevel.Minimal),
        AspNetHostingPermission(SecurityAction.InheritanceDemand,
        Level = AspNetHostingPermissionLevel.Minimal),
        DefaultProperty("swfurl"),
      ToolboxData("<{0}:wbcFlash runat=\"server\"> </{0}:wbcFlash>")]
        public class wbcFlash : WebControl
        {
     
            #region Attributs du webcontrol
     
            [Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("Chemin du FLASH"),
            Localizable(true)]
            public virtual string swfurl
            {
                get
                {
                    string s = (string)ViewState["swfurl"];
                    return (s == null) ? String.Empty : s;
                }
                set
                {
                    ViewState["swfurl"] = value;
                }
            }
     
     
     
            [Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("Url des scripts nécessaires à Flash"),
            Localizable(true)]
            public virtual string swfobjectid
            {
                get
                {
                    string s = (string)ViewState["swfobjectid"];
                    return (s == null) ? String.Empty : s;
                }
                set
                {
                    ViewState["swfobjectid"] = value;
                }
            }
     
            [Bindable(true),
            Category("Appearance"),
            DefaultValue(400),
            Description("Hauteur du flash"),
            Localizable(true)]
            public virtual int swfheight
            {
                get
                {
                    int s = 400;
                    if (ViewState["swfheight"] != null)
                    {
                        s = int.Parse(ViewState["swfheight"].ToString());
                    }
                    return s;
                }
                set
                {
                    ViewState["swfheight"] = value.ToString();
                }
            }
     
            [Bindable(true),
            Category("Appearance"),
            DefaultValue(500),
            Description("Largeur du flash"),
            Localizable(true)]
            public virtual int swfwidth
            {
                get
                {
                    int s = 500;
                    if (ViewState["swfwidth"] != null)
                    {
                        s = int.Parse(ViewState["swfwidth"].ToString());
                    }
                    return s;
                }
                set
                {
                    ViewState["Width"] = value.ToString();
                }
            }
     
            [Bindable(true),
    Category("Appearance"),
    DefaultValue(9),
    Description("Version du player flash"),
    Localizable(true)]
            public virtual int flashplayerversion
            {
                get
                {
                    int s = 500;
                    if (ViewState["flashplayerversion"] != null)
                    {
                        s = int.Parse(ViewState["flashplayerversion"].ToString());
                    }
                    return s;
                }
                set
                {
                    ViewState["flashplayerversion"] = value.ToString();
                }
            }
     
            [Bindable(true),
    Category("Appearance"),
    DefaultValue("#FFFFFF"),
    Description("Couleur de fond de l'animation flash Flash"),
    Localizable(true)]
            public virtual string swfbackcolor
            {
                get
                {
                    string s = (string)ViewState["swfbackcolor"];
                    return (s == null) ? String.Empty : s;
                }
                set
                {
                    ViewState["swfbackcolor"] = value;
                }
            }
     
            #endregion
     
            protected override void RenderContents(HtmlTextWriter writer)
            {
                // on ajoute le chargement du fichier swfobject
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "Flash", "<script language=\"JavaScript\" src=\"" + "/_Ressources/ExercicePlayer/swfobject.js\"></script> ");
     
                string v_flash = this.swfurl + "?random=" + System.Guid.NewGuid().ToString();
     
                string jscript = "";
                jscript += "\r\n<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
                jscript += "var so = new SWFObject(\"" + v_flash + "\", \"" + this.swfobjectid + "\", \"" + this.swfwidth + "\", \"" + this.swfheight + "\", \"" + this.flashplayerversion + "\", \"" + this.swfbackcolor + "\");\r\n";
                jscript += "so.write(\"flashcontent\");\r\n";
                jscript += "\r\n</script>";
     
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Flash_Movie", jscript);
            }
     
     
            public wbcFlash()
            {
            }
        }
    }
    Mais quand je l'insere dans la page, le code généré est le :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <table>
    <tr>
    <td>
    <span id="ctl00_ContentPlaceHolder1_swfrrr"></span>
    </td></tr>
    </table>
    et puis plus loin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <script language="JavaScript" type="text/javascript">
    var so = new SWFObject("/_Ressources/ExercicePlayer/index.swf?random=cc03d358-99d3-4b87-b798-a2585744074f", "index", "500", "613", "9", "#FFFFFF");
    so.write("flashcontent");
    </script>
    Je ne comprends pas pourquoi le code fait par mon RenderContents n'est pas dans mon <span id="ctl00_ContentPlaceHolder1_swfrrr"> ???

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2005
    Messages : 700
    Par défaut
    Parce qu'il faut utiliser le "HtmlTextWriter writer" pour l'insérer entre

    La tu utilises Page, qui va ajouté ton script à la fin ou au début en fonction de la méthode choisie.
    Comme tu as choisie StartUp il se place à la fin.

Discussions similaires

  1. texte ne s'affiche pas au bon endroit
    Par loustalet dans le forum Mise en page CSS
    Réponses: 10
    Dernier message: 15/04/2011, 14h10
  2. le div flottant ne s'affiche pas au bon endroit lorsque la fenetre est rétrécie
    Par Christophe93250 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 23/03/2007, 11h44
  3. Réponses: 7
    Dernier message: 02/01/2007, 16h25

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