Wednesday, July 6, 2011

To retrieve the id and Text of dynamic generate button when it get clicked in asp.net

//First create the object of Button
Button b=new Button();
//suppose i want 5 button
for(int i=0;i<5;i++)
{
 b.ID="b"+ i;
b.Text="Btn"+i;
b.Click +=new EventHandler(getvalue);
}
protected void getvalue(object sender,EventArgs e)
{
Button b1=sender as Button;
Response.Write(b1.ID);
Response.Write(b1.Text);
}
 It Will display the id and text of particular button, when it get clicked

No comments:

Post a Comment