views:

522

answers:

1

I was able to create a client script click event on a link button for normal ID's and numbers. But when I tried to do this with a string it causes a parse error. Not the difference lies on adding the single quote to enclose the Even("name") value. If the single quote is missing a javascript error occurs. If it exist, an ASPX parse error occurs. Any ideas?

<asp:DataList ID="DataList1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" 
          OnClientClick='<%# "javascript:setDialogValue('" + Eval("name") + "');return false;" %>'
          PostBackUrl="#" Text='<%# Eval("name") %>' Font-Size="Small" />
    </ItemTemplate>
</asp:DataList>
+2  A: 

I would use a double quote and escape it.

<asp:DataList ID="DataList1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" 
          OnClientClick='<%# "javascript:setDialogValue(\"" + Eval("name") + "\");return false;" %>'
          PostBackUrl="#" Text='<%# Eval("name") %>' Font-Size="Small" />
    </ItemTemplate>
</asp:DataList>
tvanfosson