Bonjour,
quelle est la difference entre ces 2 facon de faire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 ublic class OnLoGonEventArgs : EventArgs { public string _title; public OnLoGonEventArgs(string title) { _title = title; } }
EventHandler :
Dans un webusercontrol
Page aspx
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public EventHandler<OnLoGonEventArgs> OnLogon; protected void Button1_Click(object sender, EventArgs e) { if (OnLogon != null) OnLogon(sender, new OnLoGonEventArgs(TextBox1.Text)); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 protected void Page_Load(object sender, EventArgs e) { Uc1_1.OnLogon += OnLoGon; } private void OnLoGon(object sender, OnLoGonEventArgs e) { if (e._title != "") { Label1.Text = e._title; } }
Delegue:
Dans un webusercontrol
Page aspx
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public delegate void getInfo(object sender, OnLoGonEventArgs e); public event getInfo getInfoEvent; protected void Button1_Click(object sender, EventArgs e) { OnLoGonEventArgs args = new OnLoGonEventArgs(TextBox1.Text); getInfoEvent(this, args); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 protected void Page_Load(object sender, EventArgs e) { Uc2_1.getInfoEvent += new uc2.getInfo(Uc2_1_getInfoEvent); } void Uc2_1_getInfoEvent(object sender, OnLoGonEventArgs e) { Label1.Text = e._title; }
Quelle est la difference ? cela donne le meme resultat.
Merci
Partager