By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,585 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

do you know how i to create events dynamicaly?

P: n/a
hello friends, i am writing a page aspx and creating controls dinamicaly and
then
i must to create for each control the events as well.

Anybody to know how?????

happy day

lion
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
hi Lion
this should be fairly simple . the event that are associated with an
object are integrated along with them so what you need to do it .
" have the handler method ready beforehand ( even if you might not use
them , or you may have to use them with other controls )
" then when you create your control associate the appropriate handler with
the event of the control you just created
lets say for example that you are to create buttons on your page at run
time , and you want to handle the click event of these runtime buttons
first you need to have an handling method ( with the expected signature
from the handler)
lets say you declared such function as follows, this function would
change the display text of your clicked button to "clicked"
private void handle_clicks (object sender, System.EventArgs e)
{
Button k = (Button)sender ;
k.Text = " clicked " ;

}

Then, when you create you control ,associate the click event with that
hander in one assigning statement ( technically you will be creating a new
EventHandler delegate, passing the handle_clicks function to the delegate
constructor , and subscribing the delegate with the event )
Lets say you create button f at runtime as follows
Button f = new Button();
Then add the handler to its click event as follows
f.Click+= new System.EventHandler(this. handle_clicks);
and anther button m
Button m = new Button();
m.Click+= new System.EventHandler(this.handle_clicks);
hope this was clear
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

P: n/a
yes, yes.

I have associate it for the handler and that's it.

Thank's a lot

leon.
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:t7**************@cpmsftngxa06.phx.gbl...
hi Lion
this should be fairly simple . the event that are associated with an
object are integrated along with them so what you need to do it .
" have the handler method ready beforehand ( even if you might not use
them , or you may have to use them with other controls )
" then when you create your control associate the appropriate handler with the event of the control you just created
lets say for example that you are to create buttons on your page at run
time , and you want to handle the click event of these runtime buttons
first you need to have an handling method ( with the expected signature
from the handler)
lets say you declared such function as follows, this function would
change the display text of your clicked button to "clicked"
private void handle_clicks (object sender, System.EventArgs e)
{
Button k = (Button)sender ;
k.Text = " clicked " ;

}

Then, when you create you control ,associate the click event with that
hander in one assigning statement ( technically you will be creating a new EventHandler delegate, passing the handle_clicks function to the delegate
constructor , and subscribing the delegate with the event )
Lets say you create button f at runtime as follows
Button f = new Button();
Then add the handler to its click event as follows
f.Click+= new System.EventHandler(this. handle_clicks);
and anther button m
Button m = new Button();
m.Click+= new System.EventHandler(this.handle_clicks);
hope this was clear
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3

P: n/a
Hey Mohamed, thanks a lot.
I have done you words and that's it, very easy man.

thanks.

lion.
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:t7**************@cpmsftngxa06.phx.gbl...
hi Lion
this should be fairly simple . the event that are associated with an
object are integrated along with them so what you need to do it .
" have the handler method ready beforehand ( even if you might not use
them , or you may have to use them with other controls )
" then when you create your control associate the appropriate handler with the event of the control you just created
lets say for example that you are to create buttons on your page at run
time , and you want to handle the click event of these runtime buttons
first you need to have an handling method ( with the expected signature
from the handler)
lets say you declared such function as follows, this function would
change the display text of your clicked button to "clicked"
private void handle_clicks (object sender, System.EventArgs e)
{
Button k = (Button)sender ;
k.Text = " clicked " ;

}

Then, when you create you control ,associate the click event with that
hander in one assigning statement ( technically you will be creating a new EventHandler delegate, passing the handle_clicks function to the delegate
constructor , and subscribing the delegate with the event )
Lets say you create button f at runtime as follows
Button f = new Button();
Then add the handler to its click event as follows
f.Click+= new System.EventHandler(this. handle_clicks);
and anther button m
Button m = new Button();
m.Click+= new System.EventHandler(this.handle_clicks);
hope this was clear
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.