0
error: linked button The server tag is not well formed.

I am using VB asp.net and JavaScript

I have a linked button inside repeater. When user click on remove button then I want to run onclick() function and pass in a eval() value.

after that I want to get the value inside javascript function.

Note, creating hidden field wont work because it is inside repeater and there is no way for me to get the value inside JavaScript function.

function RemoveItemJS(obj) {
    alert("test" + obj);
}

vb asp.net repeater code:

<asp:Repeater ID="BagRepeater" runat="server">
    <ItemTemplate>
        <asp:HyperLink ID="ProductNameHL" NavigateUrl='<%# Eval("Product_ID", "../Shop/ShopDetail.aspx?Product_ID={0}") %>'  runat="server">
            <h4 class="Text-Spacing"><%# Eval("Name")%></h4>
        </asp:HyperLink>
        <h5><strong>$<%# Eval("Price") %></strong></h5>
        <h5>Color: <%# Eval("Color") %></strong></h5>
        <h5>Size: <%# Eval("Size") %></strong></h5>
        <h5>QTY: <%# Eval("QTY") %></strong></h5>                                   
        <asp:LinkButton ID="RemoveItemLB" OnClientClick="RemoveItemJS('"+<%# Eval("Product_ID") %>+"');" runat="server"><span class="glyphicon glyphicon-remove"></span></asp:LinkButton>
    </ItemTemplate>
</asp:Repeater>
NnN
  • 463
  • 2
  • 11
  • The answers provided here might help you: https://stackoverflow.com/questions/9415923/asp-net-link-button-server-tag-is-not-well-formed – Steve Feb 05 '18 at 01:39
  • thanks, this was helpful but i am trying to do this without refresh –  Feb 05 '18 at 01:53

2 Answers2

0

Follow the approach as below. I have tried this and it works.

  1. You need to escape the quotes inside the value of onclientclick property as in code below.
  2. Note that double quotes are escaped with a backslash i.e. \ character and also the entire JavaScript code is emitted from server-side tag.
  3. Use & as string concatenation operator in VB.Net and not + within a server-side expression in markup.

    OnClientClick='<%# "RemoveItemJS(\"" &  Eval("Product_ID") & "\")" %>'
    
Sunil
  • 20,653
  • 28
  • 112
  • 197
0

Try with 'onclick'

<asp:LinkButton ID="RemoveItemLB" onclick='<%# "RemoveItemJS(" +Eval("Product_ID") + " );" %>' runat="server"><span class="glyphicon glyphicon-remove"></span></asp:LinkButton>
NnN
  • 463
  • 2
  • 11