3

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.

Michael
  • 13,950
  • 57
  • 145
  • 288
  • quote problem.. may be.. Just a thought why dont raise event in code behind and do response.redirect since thats what you are doing? – AJP Jan 28 '12 at 00:40

2 Answers2

7
<asp:LinkButton ID="LinkButton1" runat="server" Text="edit item" onclick='AddItem.aspx?catid=<%# Eval("CollectionID")%>' />

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.

<a href='AddItem.aspx?catid=<%# Eval("CollectionID")%>'>edit item</a>

This article shows how to pass an argument to an event handler from a link button. Instead of using OnClick, you can use OnCommand and set the CommandArgument property.

In Markup

  <asp:LinkButton id="lnkEdit" 
       Text="Edit Item"
       CommandArgument='<%# Eval("CollectionID")%>'
       OnCommand="lnkEdit_Command" 
       runat="server"/>

In Codebehind

protected void lnkEdit_Command( object sender, CommandEventArgs e )
{
    // evaluate e.CommandArgument and do something with it
}

I favor using a URL versus a command event handler whenever possible as it eliminates a comparatively expensive postback.

Tim M.
  • 53,671
  • 14
  • 120
  • 163
2

You can pass param in these way.

<asp:LinkButton ID="LinkButton1" runat="server" Text="edit item" 
PostBackUrl='AddItem.aspx?catid=<%#Eval("CollectionID")%>&catname=<%#Eval("CollectionName")%>' />
Ashfaq Shaikh
  • 1,648
  • 12
  • 20