Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i have created dynamic image button ..for that i want to add onclick function .
i think i am correctly added my codings eventhougn the click funvtion does not call the event why?i have tried more possiblilities?

C#
for (int i=0;i<dt.rows.count.i++)
{

 ImageButton btn1 = new ImageButton();
                    btn1.ID = "btn1" + i;
                    btn1.ImageUrl = "images/edit.jpg";
                    btn1.Click += new ImageClickEventHandler(btn1_Click);
}


here am calling funcitonn

C#
void btn1_Click(object sender, ImageClickEventArgs e)
      {
          this.MpopupRuleEdit.Show();
      }


here the btn1-click event does not call
if i insert break point and hecked controls does not go the event why?
plz say how to solve this?reply expected soon..
Posted
Updated 3-Aug-11 20:19pm
v2
Comments
sudeshchandram 4-Aug-11 2:22am    
Your for loop present inside "Page_Load" method...????
suryaswathi 4-Aug-11 2:57am    
no outside it is seperate function
sudeshchandram 4-Aug-11 3:07am    
Is there connection between this seperate function and your page_load method? Is it getting called through a chain of functions originated from page_load method?
Sergey Alexandrovich Kryukov 4-Aug-11 2:34am    
Did you put a breakpoint on "btn1.Click += ..."?
--SA
suryaswathi 4-Aug-11 2:58am    
ya controls not go there

1 solution

I assume this is a ASP.NET issue.

So, Did you add the newly created object of Type ImageButton to the Controls( Page ControlCollection )? If not please do so,

Controls.Add(btn1);

where btn1 is the object of ImageButton.

Hope it helps :)
 
Share this answer
 
Comments
suryaswathi 4-Aug-11 3:03am    
pnlcleintSearch.Controls.Add(btn1);

i added that controls in panel also
Mohammad A Rahman 4-Aug-11 4:26am    
Could you please check your chain of method calling from the Page_Load to your dynamic control creation method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900