happysmile
happysmile

Reputation: 7777

how to call an image button event in a function

i need to call an image button event in a function. how to call

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

    }

this my function

 void  bindData()
{
// here i nee  to cal the  above image button event
}

thank you

Upvotes: 0

Views: 3356

Answers (3)

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68747

You can either use ImageButton1_Click(image, new ImageClickEventArgs(0, 0) where the image is the image you want to simulate the click event on. Or you can send in null parameters. But the best way is to create another method with the logic inside ImageButton1_Click and place a call to it inside the click event, and anywhere else that is necessary.

Upvotes: 0

Kelsey
Kelsey

Reputation: 47776

Easy:

void bindData()
{
    // here i nee  to cal the  above image button event
    ImageButton1_Click(null, null);
}

You can also send in a control as the sender argument if you want to use it and you could also send in some arguements by sending in a n ImageClickEventArgs object but neither are necessary.

Upvotes: 1

Canavar
Canavar

Reputation: 48108

Try this to call your event with empty parameters :

void  bindData()
{
    ImageButton1_Click(null, new ImageClickEventArgs(0, 0));
}

Upvotes: 3

Related Questions