do you know how i to create events dynamicaly?

  • Thread starter Thread starter leon
  • Start date Start date
L

leon

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
 
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
 
Hey Mohamed, thanks a lot.
I have done you words and that's it, very easy man.

thanks.

lion.
 
you are welcomed lion :)
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top