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 :

[VB.Net] Comment generer une page html dynamiquement ? [Trucs & Astuces]


Sujet :

ASP.NET

  1. #1
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut [VB.Net] Comment generer une page html dynamiquement ?
    bonjour,
    je suis en train de construire toute une page html avec des <table> <a> etc tout en programmation (le but etant d'obtenir une génération générique de menu).
    Je contruit les lignes, les colonnes au fur et à mesure.
    Tout fonctionne bien, sauf pour quelques elements html dont je n'ai pas trouvé l'equivalent en objet .net par programmation.
    Ainsi par exemple, je n'ai pas trouvé quel objet est l'equivalent de la puce html <LI>, et quel objet est l'equivalent du retour à la ligne <BR>.

    quelqu'un les connait ?

    (pour etre plus claire je pose un exemple de code simplifié : )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    Dim Table As System.Web.UI.WebControls.Table 'ma table <TABLE>
    Dim bgTableRow As New TableRow() 'equivalent du <TR>
    Dim bgTableCell As New TableCell() 'equivalent du <TD>
    Dim link As System.Web.UI.WebControls.HyperLink 'equivalent du <A>
     
     
    bgTableCell.Controls.Add(link) 'ajoute le <A> dans le <TD>
    'ajouter un <BR> ici et une puce ???
    bgTableRow.Controls.Add(bgTableCell) 'ajoute le <TD> dans le <TR>
    Table.Controls.Add(bgTableRow) 'ajoute le <TR> dans le <TABLE>
    merci

  2. #2
    Membre du Club
    Inscrit en
    Novembre 2002
    Messages
    35
    Détails du profil
    Informations personnelles :
    Âge : 50

    Informations forums :
    Inscription : Novembre 2002
    Messages : 35
    Points : 44
    Points
    44
    Par défaut
    Bonjour,

    Voici un petit exemple de control qui sert à demander un user et un password et qui gère l'événementiel =)

    l'interet est que tout est dans une classe...

    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
    202
    203
    204
    205
    206
    207
    208
    209
    210
     
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Web.Security;
    using AuthenticationComponent.BusinessFacade;
     
    namespace AuthenticationComponent.WebUI
    {
    	/// <summary>
    	/// Description résumée de AuthenticationControl.
    	/// </summary>
    	/// 
    	[DefaultProperty("Text"),
    	ToolboxData("<{0}:AuthenticationControl runat=server></{0}:AuthenticationControl>")]
    	public class AuthenticationControl : WebControl, INamingContainer
    	{
     
    #region Member variables
     
    		//User
    		protected Label UserLabel = new Label();
    		protected TextBox UserTextBox = new TextBox();
    		protected RequiredFieldValidator UserRequiredFieldValidator = new RequiredFieldValidator();
    		protected RegularExpressionValidator UserRegularExpressionValidator = new RegularExpressionValidator();
     
    		//Password
    		protected Label PasswordLabel = new Label();
    		protected TextBox PasswordTextBox = new TextBox();
    		protected RequiredFieldValidator PasswordRequiredFieldValidator = new RequiredFieldValidator();
    		protected RegularExpressionValidator PasswordRegularExpressionValidator = new RegularExpressionValidator();
     
    		//Persitent Cookie
    		protected Label PersistLabel = new Label();
    		protected CheckBox Persist = new CheckBox();
     
    		protected ImageButton LogonButton = new ImageButton();
     
    		protected Panel MismatchPanel = new Panel();
    		protected Label ErrMsgLabel = new Label();
     
    #endregion
     
    #region Methods and Implementation
    		public AuthenticationControl()
    		{
    			EnsureChildControls();
    		}
     
    		/// <summary>
    		/// <para>CreateChildControls add all the control need to display in the current controls when is a composed control.</para>
    		/// <seealso cref="System.Web.UI.Control.Control" />
    		/// </summary>
    		/// <param name="evt">An EventArgs that controls the event data.</param>
    		protected override void CreateChildControls()
    		{
    			// Start to add all controls
    			Table table;
    			TableRow row;
    			TableCell cell;
     
    			table = new Table();
    			table.CellPadding = 5;
    			table.CellSpacing = 0;
    			Unit unit = Unit.Percentage(100);
    			table.Width = unit;
    			Controls.Add(table);
    			// User
    			row = new TableRow();
    			table.Rows.Add(row);
    			Controls.Add(UserLabel);
    			cell = new TableCell();
    			cell.VerticalAlign = VerticalAlign.Top;
    			UserLabel.Attributes.Add("key", "UserLabel");
    			cell.Controls.Add(UserLabel);
    			row.Cells.Add(cell);
     
    			cell = new TableCell();
    			cell.Controls.Add(UserTextBox);
    			cell.Controls.Add(new LiteralControl("*<BR>"));
    			UserTextBox.ID = "UserTextBox";
    			UserTextBox.CssClass = "TextBoxStyle";
    			UserRequiredFieldValidator.Display = ValidatorDisplay.Dynamic;
    			UserRequiredFieldValidator.ID = "UserRequired";
    			UserRequiredFieldValidator.ControlToValidate = UserTextBox.ID;
    			UserRequiredFieldValidator.Attributes.Add("key", "UserRequiredFieldValidator");
    			cell.Controls.Add(UserRequiredFieldValidator);
    			UserRegularExpressionValidator.Display = ValidatorDisplay.Dynamic;
    			UserRegularExpressionValidator.ID = "UserRegExp";
    			UserRegularExpressionValidator.ValidationExpression = "[^ ]{4,40}";
    			UserRegularExpressionValidator.ControlToValidate = UserTextBox.ID;
    			UserRegularExpressionValidator.Text = "User must be 4-40 nonblank characters.";
    			UserRegularExpressionValidator.Attributes.Add("key", "UserRegularExpressionValidator");
    			cell.Controls.Add(UserRegularExpressionValidator);
    			row.Cells.Add(cell);
     
    			//Password
    			row = new TableRow();
    			table.Rows.Add(row);
    			cell = new TableCell();
    			cell.VerticalAlign = VerticalAlign.Top;
    			PasswordLabel.Attributes.Add("key", "PasswordLabel");
    			cell.Controls.Add(PasswordLabel);
    			row.Cells.Add(cell);
    			cell = new TableCell();
    			cell.Controls.Add(PasswordTextBox);
    			cell.Controls.Add(new LiteralControl("*<BR>"));
    			PasswordRequiredFieldValidator.Display = ValidatorDisplay.Dynamic;
    			PasswordTextBox.ID = "PasswordTextBox";
    			PasswordTextBox.TextMode = TextBoxMode.Password;
    			PasswordTextBox.CssClass = "TextBoxStyle";
    			PasswordRequiredFieldValidator.ID = "PasswordRequired";
    			PasswordRequiredFieldValidator.ControlToValidate = PasswordTextBox.ID;
    			PasswordRequiredFieldValidator.Attributes.Add("key", "PasswordRequiredFieldValidator");
    			cell.Controls.Add(PasswordRequiredFieldValidator);
    			PasswordRegularExpressionValidator.Display = ValidatorDisplay.Dynamic;
    			PasswordRegularExpressionValidator.ID = "PasswordRegExp";
    			PasswordRegularExpressionValidator.ValidationExpression = "[^ ]{4,40}";
    			PasswordRegularExpressionValidator.ControlToValidate = PasswordTextBox.ID;
    			PasswordRegularExpressionValidator.Text = "Password must be 4-40 nonblank characters.";
    			PasswordRegularExpressionValidator.Attributes.Add("key", "PasswordRegularExpressionValidator");
    			cell.Controls.Add(PasswordRegularExpressionValidator);
    			row.Cells.Add(cell);
     
    			//Persitent
    			row = new TableRow();
    			table.Rows.Add(row);
    			cell = new TableCell();
    			PersistLabel.Attributes.Add("key", "PersistLabel");
    			cell.Controls.Add(PersistLabel);
    			row.Cells.Add(cell);
    			cell = new TableCell();
    			cell.Controls.Add(Persist);
    			row.Cells.Add(cell);
     
    			//Logon Button
    			row = new TableRow();
    			table.Rows.Add(row);
    			cell = new TableCell();
    			cell.HorizontalAlign = HorizontalAlign.Right;
    			LogonButton.ImageUrl = "images/{0}/{1}/LogonButton.gif";
    			cell.Controls.Add(LogonButton);
    			row.Cells.Add(cell);
     
    			//Panel error
    			Controls.Add(MismatchPanel);
    			table = new Table();
    			table.CellPadding = 5;
    			table.CellSpacing = 0;
    			table.Width = unit;
    			MismatchPanel.Controls.Add(table);
    			row = new TableRow();
    			table.Rows.Add(row);
    			cell = new TableCell();
    			cell.Controls.Add(ErrMsgLabel);
    			row.Cells.Add(cell);
     
    			LogonButton.Click += new ImageClickEventHandler(OnLogin);
    		}
     
    		/// <summary>
    		///     Validates a logon attempt  saves off the customer account information.
    		///     <param name="sender">The source of the event.</param>
    		///     <param name="e">An EventArgs that contains the event data.</param>
    		/// </summary>
    		private void OnLogin(object sender, ImageClickEventArgs e)
    		{
    			MismatchPanel.Visible = false;
     
    			//Validator controls make sure Email and Password exist
    			if (!Page.IsValid)
    			{
    				return;
    			}
     
    			//
    			// Check the User and Password combination
    			//
    			long party_id = 0;
    			try
    			{
    				party_id = (new UserLoginSystem()).GetPartyByUser(UserTextBox.Text, PasswordTextBox.Text);
    			}
    			catch(ArgumentException aex)
    			{
    				ErrMsgLabel.Text = "ArgumentException : " + aex.ToString();
    				MismatchPanel.Visible = true;
    			}
    			catch(Exception ex)
    			{
    				throw new Exception("Error : ",ex);
    			}
    			finally
    			{
    				if (party_id != 0)   //were they valid?
    				{
    					FormsAuthentication.RedirectFromLoginPage(party_id.ToString(), Persist.Checked);
    				}
    				else
    				{
    					ErrMsgLabel.Attributes.Add("key", "UserNotRegistered");
    					MismatchPanel.Visible = true;
    				}        
    			}
    		}
     
    #endregion
    	}
    }

  3. #3
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut
    le code est un peu long mais tres interessant, la réponse à la question initiale semble donc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    cell.Controls.Add(new LiteralControl("<BR>"))
    merci !

  4. #4
    Membre du Club
    Inscrit en
    Novembre 2002
    Messages
    35
    Détails du profil
    Informations personnelles :
    Âge : 50

    Informations forums :
    Inscription : Novembre 2002
    Messages : 35
    Points : 44
    Points
    44
    Par défaut
    Bonjour,

    Oui c un peu long mais je me suis dis que de montrer en même temps l'approche objet à l'exemple serais assez didactique =)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [HTML] HTML Comment imbriquer une page HTML dans une autre page
    Par Gerard du Bouchonnois dans le forum Balisage (X)HTML et validation W3C
    Réponses: 9
    Dernier message: 15/06/2006, 17h11
  2. comment intégrer une page html dans swf?
    Par jeanman dans le forum Intégration
    Réponses: 3
    Dernier message: 10/05/2006, 19h36
  3. [Map] comment generer une interface graphique dynamiquement?
    Par hby dans le forum Interfaces Graphiques en Java
    Réponses: 7
    Dernier message: 20/04/2006, 16h01
  4. [VB.Net] Comment rafraichir une page aspx ?
    Par bisounux dans le forum ASP.NET
    Réponses: 3
    Dernier message: 02/02/2006, 11h25
  5. Comment générer des pages HTML dynamiques ?
    Par Devil666 dans le forum Java EE
    Réponses: 2
    Dernier message: 15/04/2005, 10h56

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