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
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace test
{
public static class HistoriqueWebForm1
{
public static List<TextBox> TextBoxCollection
{
get
{
return (List<TextBox>)HttpContext.Current.Session["TextBoxCollection"];
}
set
{
HttpContext.Current.Session["TextBoxCollection"] = value;
}
}
}
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e )
{
AddTextBox( HistoriqueWebForm1.TextBoxCollection );
}
protected void TextBox1_TextChanged( object sender, EventArgs e )
{
List<TextBox> TxBxColl = HistoriqueWebForm1.TextBoxCollection;
this.RemoveTextBox( TxBxColl );
try
{
int iNbtxtBx;
if ( Int32.TryParse( ( (TextBox)( sender ) ).Text, out iNbtxtBx ) )
{
TxBxColl.Clear();
for ( int i = 0; i < iNbtxtBx; ++i )
{
TextBox kTxBx = new TextBox();
kTxBx.ID = "TextBox_" + i.ToString();
kTxBx.Text = "Heure n° " + i.ToString();
kTxBx.Height = 30;
kTxBx.Width = 500;
kTxBx.Visible = true;
kTxBx.Enabled = true;
kTxBx.AutoPostBack = true;
TxBxColl.Add( kTxBx );
}
HistoriqueWebForm1.TextBoxCollection = TxBxColl;
AddTextBox( TxBxColl );
}
}
catch ( Exception exc )
{
Debug.WriteLine( "ERROR : " + exc );
}
}
protected void TextBoxPhrase_TextChanged( object sender, EventArgs e )
{
List<TextBox> TxBxColl = HistoriqueWebForm1.TextBoxCollection;
this.RemoveTextBox( TxBxColl );
TextBox kTxBx = ( (TextBox)( sender ) );
int iStart = TxBxColl.IndexOf( kTxBx );
for ( int i = iStart; i < TxBxColl.Count; ++i )
{
TxBxColl[i].Text = kTxBx.Text;
}
HistoriqueWebForm1.TextBoxCollection = TxBxColl;
AddTextBox( TxBxColl );
}
protected void AddTextBox( IList<TextBox> TextBoxList )
{
IEnumerator kEnumerator = TextBoxList.GetEnumerator();
TextBox kTxBx;
while ( kEnumerator.MoveNext() )
{
kTxBx = ( (TextBox)( kEnumerator.Current ) );
kTxBx.TextChanged += new EventHandler( this.TextBoxPhrase_TextChanged );
this.form1.Controls.Add( kTxBx );
}
}
protected void RemoveTextBox( IList<TextBox> TextBoxList )
{
IEnumerator kEnumerator = TextBoxList.GetEnumerator();
while ( kEnumerator.MoveNext() )
{
this.form1.Controls.Remove( ( (TextBox)( kEnumerator.Current ) ) );
}
}
}
} |