Click here to Skip to main content
15,887,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Iam creating a linkbutton in the button click .and adding click event in the for the linkbutton in the button itsself but the problem is when i click onthe button like button is getting created but the event handler is not adding to the button and on click of the linkbutton it is getting disabled.how to resolve this ...kindly help in this regard


here is my sample code

C#
protected LinkButton lbl;
    protected void Page_Load(object sender, EventArgs e)     
       {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        lbl = new LinkButton();
        lbl.Text = "hai";
        lbl.ID = "ll";
        pnl.Controls.Add(lbl);
        lbl.Click +=new EventHandler(lbl_Click);
       
    }
    protected void lbl_Click(object s, EventArgs e)
    { 
      Response.Write("Event Calling");
    }
Posted
Updated 17-Oct-11 23:42pm
v2

You must create the LinkButton on every postback. If it doesn't exist in the Page, the event cannot fire.
 
Share this answer
 
You might need to add the following:

C#
lbl = new LinkButton();
lbl.Text = "hai";
lbl.ID = "ll";

//this line
lbl.AutoPostBack = true;

pnl.Controls.Add(lbl);
lbl.Click +=new EventHandler(lbl_Click);


More info:

http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx[^]
 
Share this answer
 

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