Home > Software engineering >  Set value for HTML control attribute marked as run at server
Set value for HTML control attribute marked as run at server

Time:09-16

Asp.Net Web Forms stops rendering value of <%#: Item %> for HTML control attribute once control is marked as run at server. Herewith snippet of Repeater ItemTemplate:

<a id="RepeaterElement" runat="server" href="?code=<%#: Item %>"><%#: Item %></a>

The resulting HTML code instead of href="?code=MyValue" becomes literally what it is behind the scenes href="?code=<%#: Item %>".

How can I manipulate with attributes of HTML control marked as run at server from .aspx file within Repeater Item?

CodePudding user response:

You are close, but you need the ?code= in the databinding expression.

<asp:Repeater ID="Repeater1" runat="server" ItemType="System.String">
    <ItemTemplate>

        <a id="RepeaterElement" runat="server" href='<%# "?code="   Item %>'><%# Item %></a>

    </ItemTemplate>
</asp:Repeater>
  • Related