我不知道问题的名字……. [英] I do not know the name of the problem.......

查看:84
本文介绍了我不知道问题的名字…….的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个大而奇怪的问题,
在我的网站中,代码无法正常运行,
因此,我采用了该代码并将其放在网站的小示例中,然后它可以正常工作
但是在我的原始网站上有很多页面,但是无法正常工作,为什么?我不知道.

那是我的代码:

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:

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



问题是:
在运行时,调用方不会转到方法:lbtnHomeSpecificTopic_Click.

谢谢



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

Thanks

推荐答案

我认为,每当您的页面有服务器请求时,它都会创建LinkBut​​ton.我认为它不需要&这可能是此问题的原因.你可以试试看.
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");
    }


您在Page Load事件中创建了LinkBut​​ton对象,但是您从未将其添加到Page本身中,因此无需单击任何内容.您需要添加
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.


hi,

我不是你的问题,但我认为这很想念



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

Page.Controls.Add(lbtnHomeTopicAddress);



如果您需要更多信息,可以继续
http://msdn. microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.linkbutton%28v=VS.80%29.aspx [



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


这篇关于我不知道问题的名字…….的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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