如何将参数传递给链接按钮控件中的 Eval()?
ASP 声明:
<asp:LinkButton ID="LinkButton1" runat="server" Text="edit item" onclick="'AddItem.aspx?catid=<%# Eval("CollectionID")%>'"></asp:LinkButton>
我收到错误: 服务器标记的格式不正确。
LinkButton 脱花有什么问题? 先感谢您。
ASP Declaration:
<asp:LinkButton ID="LinkButton1" runat="server" Text="edit item" onclick="'AddItem.aspx?catid=<%# Eval("CollectionID")%>'"></asp:LinkButton>
I get Error:
The server tag is not well formed.
what the problem with LinkButton decloration?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我删除了
OnClick
属性值周围的无关引号。但是,
OnClick
需要委托,而不是 URL。使用超链接或切换到事件处理程序。本文展示了如何从链接按钮将参数传递给事件处理程序。您可以使用
OnCommand
并设置CommandArgument
属性,而不是使用OnClick
。在标记中
在代码隐藏中
我倾向于尽可能使用 URL 而不是命令事件处理程序,因为它消除了相对昂贵的回发。
I removed extraneous quotes around the attribute value for
OnClick
.However,
OnClick
expects a delegate, not a URL. Either use a hyperlink or switch to an event handler.This article shows how to pass an argument to an event handler from a link button. Instead of using
OnClick
, you can useOnCommand
and set theCommandArgument
property.In Markup
In Codebehind
I favor using a URL versus a command event handler whenever possible as it eliminates a comparatively expensive postback.
您可以通过这些方式传递参数。
You can pass param in these way.