开发者

Click event not work properly

开发者 https://www.devze.com 2023-01-23 12:10 出处:网络
In my website I wrote that code: protected void Page_Load(object sender, EventArgs e){LinkButton lbtnTopicAddress = new LinkButton();lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;}

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

}

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开发者_JAVA技巧 only in one page.

i added that code to many page in website but it worded only in one page every page has its specific code and no relation between them I hope you understand me thanks

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


Did you mean to miss off a ;and a } here?

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

I assume you've put a breakpoint in to ensure it isn't being fired?

I'm not exactly sure but I've got a feeling that instead of Page_Load you need to use Page_Init so your code would look this this:

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

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

p.s. 5 mins formatting your code can work wonders when trying to debug


Are you adding the button to the controls on your page, or are you trying to find the "lbtnTopicAddress" control on your page?

Simply declaring the button won't do anything -- you have to get a reference to the control itself from the page.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号