connersz
connersz

Reputation: 1213

The server tag is not well formed - hyperlink databound

I have a formatting issue with my hyperlink, it works OK with the text part along so I know it's an issue with the JavaScript but don't know what the problem is.

<asp:TemplateField>
    <ItemTemplate>
        <asp:HyperLink ID="hypCustType" runat="server" 
            Text='<%# DataBinder.Eval(Container.DataItem, "CustType") %>'
            NavigateUrl="javascript:sendval('<%# DataBinder.Eval(Container.DataItem, "CustType") %>');">
        </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

Upvotes: 0

Views: 1648

Answers (3)

giammin
giammin

Reputation: 18958

replace the asp:hyperlink with a normal html tag link:

<a href="javascript:sendval('<%# DataBinder.Eval(Container.DataItem, "CustType") %>');">
            <%# DataBinder.Eval(Container.DataItem, "CustType") %>'</a>

Upvotes: 1

RononDex
RononDex

Reputation: 4173

'The problem is, you have closed the string in the NavigateUrl Property. You should use ' or \" inside of inline code to not end the string. So you should try this:

<asp:TemplateField>
    <ItemTemplate>
        <asp:HyperLink ID="hypCustType" runat="server" 
            Text='<%# DataBinder.Eval(Container.DataItem, "CustType") %>'
            NavigateUrl="javascript:sendval('<%# DataBinder.Eval(Container.DataItem, \'CustType\') %>');">
        </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

Upvotes: 4

nphx
nphx

Reputation: 1427

Try it like this:

<asp:HyperLink ID="hypCustType" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustType") %>' NavigateUrl='<%# "javascript:sendval(\"" + DataBinder.Eval(Container.DataItem, "CustType") + "\");" %>'></asp:HyperLink>

Upvotes: 1

Related Questions