点击事件无法正常运行 [英] Click event not work properly

查看:48
本文介绍了点击事件无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的网站上,我写了以下代码:

Hi everybody,

In my website I wrote that code:

protected void Page_Load(object sender, EventArgs e)
{
  LinkButton lbtnTopicAddress = new LinkButton();
  lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;
}





protected void lbtnSpecificTopic1_Click(object sender, EventArgs e)
{
  Server.Transfer("~/SpecificTopic.aspx");
}



但是当我在运行时按链接时,调用者不会转到EventHandler方法.

为什么?

请注意,
我在同一个网站的许多页面中都编写了这样的代码,但仅在一页中起作用.

我需要帮助.



But when I press on the link in run time, the caller doesn''t go to the EventHandler method.

Why?

Note,
I wrote code like that in many pages in the same website but it work only in one page.

I need help pleaseeeeeeee..........................

My problem is that :
the code run good in one page only
but in other pages the same code not work

推荐答案

lbtnTopicAddress.单击+ = new.您必须使用new来初始化事件
lbtnTopicAddress.Click += new .You must use new to initialize a event




由于您仅在本地声明LinkBut​​ton"lbtnTopicAddress",因此该方法不起作用.

试试:

Hi,

this doesn''t work since you declare the LinkButton "lbtnTopicAddress" only locally.

Try:

LinkButton lbtnTopicAddress = new LinkButton();

protected void Page_Load(object sender, EventArgs e)    
{  
  lbtnTopicAddress.Click += new System.EventHandler(this.lbtnSpecificTopic1_Click);
}



如果仅在本地声明LinkLabel,然后不将其添加到父控件中,则无论如何都不应显示它.



If you declare the LinkLabel only locally and then don''t add it to the parent control it shouldn''t be displayed anyway.


在下面的代码中使用此代码..,

Use this code below ..,

protected void Page_Load(object sender, EventArgs e)
{
    LinkButton lbtnTopicAddress = new LinkButton();
    lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;
    lbtnTopicAddress.Text = "Click me";
    form1.Controls.AddAt(0, lbtnTopicAddress);
}
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e)
{
    Server.Transfer("~/SpecificTopic.aspx");
}


这篇关于点击事件无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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