[英]linkbutton onclick event not firing in asp net
I know this is a repeated question however, it seems a different situation. 我知道这是一个重复的问题,但情况似乎有所不同。 I have a link button on my aspx page whose event
protected void LinkButton1_Click(object sender, EventArgs e)
is not firing 我的aspx页面上有一个链接按钮,其事件
protected void LinkButton1_Click(object sender, EventArgs e)
未触发
<form>
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" causesvalidation="false"><a href="Product.aspx?id=<%#Eval("ItemCode") %>">LinkButton</a></asp:LinkButton>
</form>
Here <asp:LinkButton
has a green underline stating Element 'asp:LinkButton' is missing required attribute 'runat'
When I put runat="Server" it gives me error that: <asp:LinkButton
带有绿色下划线,表示Element 'asp:LinkButton' is missing required attribute 'runat'
当我将runat =“ Server”放到它时,出现以下错误:
Control 'Repeater1_LinkButton1_0' of type 'LinkButton' must be placed inside a form tag with runat=server.
类型为“ LinkButton”的控件“ Repeater1_LinkButton1_0”必须置于带有runat = server的表单标记中。
And when I put <Form runat="Server">
it gives me 当我放
<Form runat="Server">
它给了我
A page can have only one server-side Form tag.
一个页面只能有一个服务器端Form标记。
I am not sure if that is creating an issue. 我不确定这是否造成了问题。 Please help
请帮忙
Answering your question from comments. 通过评论回答您的问题。
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="yourCommand" CommandName="AddToCart" CommandArgument='<%#Eval("itemID")%>'>Click here</asp:LinkButton>
And in your code-behind: 并且在您的代码背后:
protected void yourCommand(object sender, CommandEventArgs e)
{
int myID = int.Parse(e.CommandArgument.ToString());
}
May i know Why you are putting a reference tag (href)inside the link button tag. 我可以知道为什么要在链接按钮标签内放置参考标签(href)。 I think this is not right, try this,
我认为这是不对的,尝试一下,
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" causesvalidation="false"></asp:LinkButton>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.