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

In my website I wrote that code:

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


C#
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 need help pleaseeeeeeee..........................

CSS
My problem is that :
the code run good in one page only
but in other pages the same code not work
Posted
Updated 3-Nov-10 2:16am
v6

lbtnTopicAddress.Click += new .You must use new to initialize a event
 
Share this answer
 
Comments
MrLonely_2 3-Nov-10 4:57am    
I try it but it not worked
Are i need to use delegate ?
and if i need it what is the code ?
AngelLoose 3-Nov-10 5:33am    
such as:this.OnCheckInput += new EMMS.Client.UILayer.Base.Delegate_OnCheckInput(this.FrmIdentityInfoEdit_OnCheckInput);
You can write in load function
MrLonely_2 3-Nov-10 7:07am    
the same problem still
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);
}


If you declare the LinkLabel only locally and then don't add it to the parent control it shouldn't be displayed anyway.
 
Share this answer
 
v3
Comments
MrLonely_2 3-Nov-10 4:39am    
Hi guy,
I added my to thr parent control and i added it locally and it worked very good
But it does in one page only
Because 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
MrLonely_2 3-Nov-10 4:39am    
Hi guy, I added my LinkLabel to thr parent control and i added it locally and it worked very good But it does in one page only Because 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
Use this code below ..,

C#
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");
}
 
Share this answer
 
Comments
MrLonely_2 3-Nov-10 8:17am    
the same problem still

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