Reputation: 619
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
<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:
Control 'Repeater1_LinkButton1_0' of type 'LinkButton' must be placed inside a form tag with runat=server.
And when I put <Form runat="Server">
it gives me
A page can have only one server-side Form tag.
I am not sure if that is creating an issue. Please help
Upvotes: 0
Views: 4964
Reputation: 711
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());
}
Upvotes: 2
Reputation: 300
May i know Why you are putting a reference tag (href)inside the link button tag. I think this is not right, try this,
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" causesvalidation="false"></asp:LinkButton>
Upvotes: 0