为LinkBut​​ton定义命令 [英] Defining a Command for a LinkButton

查看:62
本文介绍了为LinkBut​​ton定义命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正试图将LinkBut​​ton控件添加到网络表单中。我这样做的事情就像:b / b
for(i = 1; i< = someVariable; i ++)

{

LinkBut​​ton PageLink = new LinkBut​​ton();

PageLink.CommandName = i.ToString();

PageLink.Text =" Page" + i;


PageLink.Command + = PageLink_Click;

}

问题在于最后一道。我正在尝试做的是指定

当LinkBut​​ton被点击时,后面的代码中需要调用什么方法。但它在编译时会产生错误。

请帮助,

谢谢

Hi,
I''m trying to dinamically add LinkButton Controls to a web form. I do
something like:

for(i=1;i<=someVariable;i++)
{
LinkButton PageLink = new LinkButton();
PageLink.CommandName = i.ToString();
PageLink.Text = "Page " + i;

PageLink.Command += PageLink_Click;
}
The problem is with the last lane. What I''m trying to do there is to specify
what methon in the code behind needs to called when the LinkButton is
clicked. But it generates an error at compilation.
Please Help,
Thank you

推荐答案

LinkBut​​ton.Command需要一个CommandEventHandler。尝试将该行转换为:

PageLink.Command + = new CommandEventHandler(PageLink_Click);


希望有所帮助。


-

Jason Whitted


" Vi"写道:
LinkButton.Command requires a CommandEventHandler. Try chaning that line to:
PageLink.Command += new CommandEventHandler(PageLink_Click);

Hope that helps.

--
Jason Whitted

"Vi" wrote:

我正在努力将LinkBut​​ton控件添加到Web表单中。我做了类似的事情:

for(i = 1; i< = someVariable; i ++)
{Link /> LinkBut​​ton PageLink = new LinkBut​​ton();
PageLink.CommandName = i.ToString();
PageLink.Text =" Page" + i;

PageLink.Command + = PageLink_Click;
}
问题在于最后一道。我正在尝试做的是指定当单击LinkBut​​ton时需要调用的代码中的什么方法。但它在编译时会产生错误。
请帮助,
谢谢
Hi,
I''m trying to dinamically add LinkButton Controls to a web form. I do
something like:

for(i=1;i<=someVariable;i++)
{
LinkButton PageLink = new LinkButton();
PageLink.CommandName = i.ToString();
PageLink.Text = "Page " + i;

PageLink.Command += PageLink_Click;
}
The problem is with the last lane. What I''m trying to do there is to specify
what methon in the code behind needs to called when the LinkButton is
clicked. But it generates an error at compilation.
Please Help,
Thank you



尝试:


PageLink.Command + = new CommandEventHandler(PageLink_Click);


另外,我假设你只出现了部分代码,但是你要添加这个

以某种方式控制页面。最后,你需要确保在回发时重新创建

,以便事件处理程序能够连接起来因此

fire。


Karl


-

我的ASP.Net教程
http://www.openmymind.net/

Vi < Vi@discussions.microsoft.com>在消息中写道

新闻:1D ********************************** @ microsof t.com ...
Try:

PageLink.Command += new CommandEventHandler(PageLink_Click);

Also, I assume you only showed up part of the code, but you are adding this
control to the page somehow..and finally, you need to make sure to recreate
these on postback in order for the event handler to get hooked up and thus
fire.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Vi" <Vi@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...

我正在努力将LinkBut​​ton控件添加到Web表单中。我做了类似的事情:

for(i = 1; i< = someVariable; i ++)
{Link /> LinkBut​​ton PageLink = new LinkBut​​ton();
PageLink.CommandName = i.ToString();
PageLink.Text =" Page" + i;

PageLink.Command + = PageLink_Click;
}
问题在于最后一道。我正在尝试做的是
指定单击LinkBut​​ton时需要调用的代码中的哪个方法。但它在编译时会产生错误。
请帮助,
谢谢
Hi,
I''m trying to dinamically add LinkButton Controls to a web form. I do
something like:

for(i=1;i<=someVariable;i++)
{
LinkButton PageLink = new LinkButton();
PageLink.CommandName = i.ToString();
PageLink.Text = "Page " + i;

PageLink.Command += PageLink_Click;
}
The problem is with the last lane. What I''m trying to do there is to specify what methon in the code behind needs to called when the LinkButton is
clicked. But it generates an error at compilation.
Please Help,
Thank you



我做到了,但是当我在单击LinkBut​​ton,表单将被回发,

但不会调用处理程序方法PageLink_Click。知道为什么吗?


再次感谢


" JWhitted"写道:
I did that, but when I''m clicking the LinkButton, the form gets posted back,
but the handler method PageLink_Click is not called. Any idea why?

Thanks again

"JWhitted" wrote:
LinkBut​​ton.Command需要一个CommandEventHandler。尝试将该行转换为:
PageLink.Command + = new CommandEventHandler(PageLink_Click);

希望有所帮助。

-
Jason Whitted

Vi写道:
LinkButton.Command requires a CommandEventHandler. Try chaning that line to:
PageLink.Command += new CommandEventHandler(PageLink_Click);

Hope that helps.

--
Jason Whitted

"Vi" wrote:

我正在努力将LinkBut​​ton控件添加到Web表单中。我做了类似的事情:

for(i = 1; i< = someVariable; i ++)
{Link /> LinkBut​​ton PageLink = new LinkBut​​ton();
PageLink.CommandName = i.ToString();
PageLink.Text =" Page" + i;

PageLink.Command + = PageLink_Click;
}
问题在于最后一道。我正在尝试做的是指定当单击LinkBut​​ton时需要调用的代码中的什么方法。但它在编译时会产生错误。
请帮助,
谢谢
Hi,
I''m trying to dinamically add LinkButton Controls to a web form. I do
something like:

for(i=1;i<=someVariable;i++)
{
LinkButton PageLink = new LinkButton();
PageLink.CommandName = i.ToString();
PageLink.Text = "Page " + i;

PageLink.Command += PageLink_Click;
}
The problem is with the last lane. What I''m trying to do there is to specify
what methon in the code behind needs to called when the LinkButton is
clicked. But it generates an error at compilation.
Please Help,
Thank you



这篇关于为LinkBut​​ton定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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