链接按钮和事件句柄问题 [英] linkbutton and event handle problem

查看:113
本文介绍了链接按钮和事件句柄问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在按钮单击中创建一个链接按钮.并在按钮本身中为链接按钮添加单击事件,但是问题是当我单击按钮时,就像创建按钮一样,但事件处理程序未添加到按钮上并单击链接按钮正在被禁用.如何解决此问题.在这方面请提供帮助


这是我的示例代码

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

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");
    }

推荐答案

您必须在每个回发中创建LinkBut​​ton.如果Page中不存在该事件,则无法触发该事件.
You must create the LinkButton on every postback. If it doesn''t exist in the Page, the event cannot fire.


您可能需要添加以下内容:

You might need to add the following:

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

//this line
lbl.AutoPostBack = true;

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



更多信息:

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



More info:

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


这篇关于链接按钮和事件句柄问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆