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

I have big and strange problem,
in my website there is code not work properly,
so, i take that code and put it in small example of website then it work properly
But in my origin website which have many pages, it do not work properly, why?? I do not know.

that is my code:

C#
protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton lbtnHomeTopicAddress = new LinkButton();

        lbtnHomeTopicAddress.Text = "Click here";

        lbtnHomeTopicAddress.Click += new EventHandler(this.lbtnHomeSpecificTopic_Click);

        Page.Controls.Add(lbtnHomeTopicAddress);
    }

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


the problem is:
in run time the caller does not go to the method: lbtnHomeSpecificTopic_Click .

Thanks
Posted
Updated 4-Nov-10 4:11am
v5

I think, every time your page has a server request, it create the LinkButton. I think it does not need & it may be the reason of this problem. You can try this.
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        LinkButton lbtnHomeTopicAddress = new LinkButton();

        lbtnHomeTopicAddress.Text = "Click here";

        lbtnHomeTopicAddress.Click += new EventHandler(this.lbtnHomeSpecificTopic_Click);

        Page.Controls.Add(lbtnHomeTopicAddress);
       }
    }

    protected void lbtnHomeSpecificTopic_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/SpecificTopic.aspx");
    }
 
Share this answer
 
Comments
MrLonely_2 4-Nov-10 11:38am    
Thank you very much,
your think is not right exactly but it tell me where the problem.
I will explain the problem, please follow me.
shakil0304003 4-Nov-10 12:02pm    
ok :)
You create the LinkButton object in your Page Load event but you never add it to the Page itself, so there is nothing to click. You need to add
Page.Controls.Add( lbtnHomeTopicAddress )
for the instance of the button you created to appear on the page.
 
Share this answer
 
Comments
MrLonely_2 4-Nov-10 9:42am    
no man , i do not write my complete code. I make that in my code and you must notes that i said that the code run nicely in small website.
I modified my question for you
ok
hi,

I don't your problem but i think it miss this

Page.Controls.Add(lbtnHomeTopicAddress);


if you need more informations you can go on
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.linkbutton%28v=VS.80%29.aspx[^]

jerem
 
Share this answer
 
Comments
MrLonely_2 4-Nov-10 9:52am    
oh my god, it is not my problem please understand me right i write the code in good way and it work properly in small website, but in my origin website not work
JeremH 4-Nov-10 9:56am    
you can add lbtnHomeTopicAddress.Click += new EventHandler(this.lbtnHomeSpecificTopic_Click);
MrLonely_2 4-Nov-10 10:12am    
i tried but not succeeded too,
i think it is not from the code

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