MrMustafa
MrMustafa

Reputation: 305

Click event not work properly

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 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..........................

Upvotes: 0

Views: 88

Answers (2)

jwheron
jwheron

Reputation: 2562

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.

Upvotes: 0

m.edmondson
m.edmondson

Reputation: 30922

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

Upvotes: 1

Related Questions