Click to See Complete Forum and Search --> : Dynamically Activate Button


hume.tony
02-27-2009, 11:02 AM
I am trying to figure out how to dynamically activate a button in the code behind. For example, when LinkButton4 is clicked it activates LinkButton4_Click but when I try to call LinkButton4_Click(); it doesn't work.

protected void LinkButton4_Click(object sender, EventArgs e)
{
}

I figure I need to give it the (object sender, EventArgs e) parameters it's looking for I just don't know what they are.

chazzy
02-27-2009, 06:29 PM
if your code doesn't use them, you could just pass null. or use a delegate approach where LinkButton4_Click and this code behind method both call the same no arg method.

lmf232s
03-04-2009, 04:46 PM
if the code that your going to put in the click event needs to be called and executed from other parts of your application or code then I would suggest wrapping the code in the ClickEvent in its own method. This way you can call it from any where.

public Click Event(blah, blah){
CallDoSomething();
}

public pageload(.........){
CallDoSomething();
}

public CallDoSomething(){
'Code to execute
}

JoeyD
03-29-2009, 09:57 PM
do this:

LinkButton4_Click(this.LinkButton4, null);