Saturday, December 24, 2011

Dynamic Button in Asp.net

To generate dynamic Button, use Button class

Example
write code in page_load event


Button btn;
protected void Page_load(Object sender,EventArgs e)
{
               btn =new Button();
                btn.id="btn1";
                btn.Text="Submit";
                                                                    // ButtonEvent in a method,it fire when button is  pressed
                btn.Click + =new EventHandler(ButtonEvent); 
}


private void ButtonEvent(Object sender,EventArgs e)
{
             btn=sender as Button;
             Response.Write(btn.Id); 


O/P
When Button (Submit) is click, it will display id of button
Result
btn1


For CheckBoxList: Click to View





No comments:

Post a Comment